Título: NIBBLE MIRRORING ROUTINE Publicado por: SapphiRe_MSX en 14 de Mayo de 2008, 11:42:35 am 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: Código: ; 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: Código: 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. Título: BCD to ASCII conversion Publicado por: GuyveR800 en 14 de Mayo de 2008, 04:39:56 pm Nice routine!
RLD and RRD are really nice instructions in situations where they are useful :P Here's a routine I wrote for BCD string to ASCII conversion: Código: ; In: ; HL = Pointer to BCD string ; DE = Pointer to ASCII string ; B = Size of BCD string in bytes BCD2ASCII: ld a,30h .loop: rld ld [de],a inc de rld ld [de],a inc de rld inc hl djnz .loop ret |