Hi all:
Imagine you have a stream of nibbles and you want to mirror them. For instance you have the values:
F3 01 DE EF E4 24
and you want to obtain
42 4E FE ED 10 3F
Next routine is useful to do that if the bytes you want to mirror are located in ram:
; INPUT
; hl -> pointer to the first byte to be mirrored
; de -> pointer to the last byte to be mirrored
; b -> number of byte-pairs to be mirrored
MIRRORNIBBLES:
RLD
EX DE,HL
RRD
EX DE,HL
RLD
EX DE,HL
RRD
EX DE,HL
RLD
INC HL
DEC DE
DJNZ MIRRORNIBLES
RET
So, in the previous example, if the bytes are located at $C000, the code to call this routine is:
LD HL,$C000 ; HL points to $F3
LD DE,$C005 ; DE points to $24
LD B,3 ; 6 bytes to be mirrored (three pairs)
CALL MIRRORNIBBLES
Warning! This routine does not work if DE = HL, but works fine otherwise.
It only changes HL, DE and B, the value of A remains the same.
Hope you find useful the routine
--
Sph.