I have a byte loaded into A as follows:
LD A,(variable)
And I want to swap the following bits X and Y over in the byte - for example:
128 64 32 16 8 4 2 1
0 0 X X X Y Y Y
becomes
128 64 32 16 8 4 2 1
0 0 Y Y Y X X X
Any ideas?
All registers are available and ideally the result will end up in A.
No tables please, so I realise it'll probably be a combination of bit shifting (RRA etc) and OR and AND but can't think of the fastest way...?!
Maybe something along the lines of:
; A = %00XXXYYY
add a,a
add a,a
; A = %XXXYYY00
add a,a
ld c,a
; C = A = %XXYYY000, Carry X
adc a,a
adc a,a
adc a,a
; A = %YY000XXX, Carry Y
add a,c
and %00111111
; A = %00YYYXXX
; 10µs
Nice idea!! A RRCA approach wouldn't be more quick here :)
Quote from: Grim on 00:00, 18 February 13
Maybe something along the lines of:
Thanks Grim, that's great.
Nice use of the carry as a buffer.