Karoshi MSX Community
05 de Julio de 2021, 10:47:19 am *
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: 16bit unsiged + 8bit unsigned  (Leído 4581 veces)
0 Usuarios y 1 Visitante están viendo este tema.
theNestruo
Karoshi Lover
***
Mensajes: 236


Email
« : 22 de Junio de 2012, 09:11:53 pm »

Hi!
A snippet for the beginners like me Wink

To add an 8 bit value (a) to a 16 bit register (hl) I used to do this:
Código:
; hl += a
ld d,0
ld e,a
add hl,de
That takes 22 cycles and destroys an additinoal register (de).

There is a way to do the addition without using any additional register, slightly faster (20 cycles) but 1 byte longer:
Código:
; hl += a
add a,l
ld l,a
adc a,h
sub l
ld h,a
Note that bc register or de register can be used instead of hl.
En línea

theNestruo."Old BASIC programmers never die; they GOSUB but never RETURN."
nanochess
Karoshi Lover
***
Mensajes: 141


Programando algo buenísimo :)


WWW
« Respuesta #1 : 24 de Junio de 2012, 06:09:26 pm »

Very optimized  Smiley. Well done!
En línea

Mira mis juegos MSX/Colecovision/Atari/Intellivision http://nanochess.org/retro_es.html, y sígueme en Twitter http://twitter.com/nanochess
theNestruo
Karoshi Lover
***
Mensajes: 236


Email
« Respuesta #2 : 24 de Junio de 2012, 08:03:34 pm »

Oh, not mine; just found on the internet. Can't remember where; maybe here.
Strangely, it is not in the classical "Z80 maths" pages Huh That's why I put it here.
En línea

theNestruo."Old BASIC programmers never die; they GOSUB but never RETURN."
Mortimer
Karoshi Lover
***
Mensajes: 216


WWW
« Respuesta #3 : 24 de Junio de 2012, 09:45:55 pm »

But, What about the extra M1 cycle? In a MSX, both routines take 25 cycles, so the advantage is reduced to don't destroy aditional registres at price of one byte longer.
En línea
theNestruo
Karoshi Lover
***
Mensajes: 236


Email
« Respuesta #4 : 25 de Junio de 2012, 09:56:19 am »

You're right. I'm a newbie; I forgot about the M1 cycle Sad
Anyway, it's still useful if other registers cannot be detroyed (the push/pop pair would make the code longer and slower) or if the operation to accomplish is bc+=a or de+=a.
En línea

theNestruo."Old BASIC programmers never die; they GOSUB but never RETURN."
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!