Autor Tema: Mask / merge two bytes  (Leído 5488 veces)

0 Usuarios y 1 Visitante están viendo este tema.

theNestruo

  • Karoshi Lover
  • ***
  • Mensajes: 236
    • Email
Mask / merge two bytes
« en: 18 de Octubre de 2013, 07:38:14 pm »
Hi!

Don't know if reinventing the wheel but...

Código: [Seleccionar]
; Overwrites [hl] with a, but only the bits specified by b.
; i.e.: [hl] = a = ([hl] & not(b)) | (a & b)
; param hl: destination address
; param a: value to set
; param b: mask
; return a: value set
LD_HL_A_WITH_MASK:
    xor [hl]
    and b
    xor [hl]    ; ...15 tstates, 3 bytes
    ld  [hl], a ; ...23 tstates, 4 bytes (remove if not needed)
    ret         ; ...34 tstates, 5 bytes

If the mask is and known at compile time, and b can be replaced by and $nn.

And, of course, the original value can be accesed through [ix+n] or [iy+n] instead of [hl]. Or be in a register (c, d, e) instead of RAM.
« Última modificación: 18 de Octubre de 2013, 08:03:04 pm por theNestruo »
theNestruo."Old BASIC programmers never die; they GOSUB but never RETURN."