Título: Get nibbles from a byte Publicado por: jltursan en 02 de Octubre de 2006, 07:22:05 pm This routine is great when you have a lot of byte packed data :
Código: ;------------------------------------------------------ ; ; Description: Divide a byte in a pair of nibbles (4 bits) ; In: A=byte ; Out: A=high nibble, C=low nibble ; Modifies: AF,AF',C ; ;------------------------------------------------------ GET_NIBBLES: ld c,a and $F0 rrca rrca rrca rrca ex af,af' ld a,c and $0F ld c,a ex af,af' ret Hope you find it useful! :) Título: Re: Get nibbles from a byte Publicado por: SapphiRe en 21 de Octubre de 2006, 12:03:05 pm Nice! But it can be done faster if original data is in RAM:
Código: ;------------------------------------------------------ ; Input: hl = Pointer to data ; Output: d = high nibble, e = low nibble ; Modifies: a, d, e ;------------------------------------------------------ GET_NIBBLES: xor a rrd ld e,a rrd ld d,a rrd ret Ideal to use HL as a pointer to unpack the byte-packed data and BC as a counter. What do you think? ;) Of course if data is not in RAM you can add this lines Código: ;------------------------------------------------------ ; Input: a = data ; Output: d = high nibble, e = low nibble ; Modifies: a, de, hl ;------------------------------------------------------ GET_NIBBLESROM: ld hl,FREEBYTEINRAM ; you need to reserve a byte in ram to do this ld [hl],a jp GET_NIBBLES ; or place the appropriate code here |