Karoshi MSX Community
05 de Julio de 2021, 04:17:34 pm *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: Get nibbles from a byte  (Leído 3706 veces)
0 Usuarios y 1 Visitante están viendo este tema.
jltursan
Karoshi Forum's Guru
*******
Mensajes: 1516


¿Que es lo que has aprendido hoy?


WWW Email
« : 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!  Smiley
En línea

Doom dee doom dee doom
SapphiRe
Visitante
« Respuesta #1 : 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? Wink

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
« Última modificación: 21 de Octubre de 2006, 12:07:29 pm por SapphiRe » En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!