Zeda

atou24

May 19th, 2021 (edited)
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; This is intended for the eZ80, not the Z80 (it will work, just not as efficiently, and only for 16 bits).
  2. ; For a Z80 version, see https://github.com/Zeda/Z80-Optimized-Routines/blob/master/conversion/uitoa_16.z80
  3. ;
  4. ; This expects to be called in ADL mode.
  5.  
  6. atou24:
  7. ;Inputs:
  8. ;   IX points to the base-10 string
  9. ;Outputs:
  10. ;   IX points to the first non-digit byte
  11. ;   HL is the 24-bit number
  12. ;       Note that if the input exceeds 24 bits, input%2^24 is returned
  13. ;Destroys:
  14. ;   AF, BC, DE
  15. ;
  16. ;Set HL and DE to 0
  17.   or a
  18.   sbc hl,hl
  19.   ex de,hl
  20.   sbc hl,hl
  21.   jr .loop_start
  22. .loop:
  23.   inc ix
  24.  
  25. ; multiply HL by 10
  26.   push hl
  27.   pop bc
  28.   add hl,hl
  29.   add hl,hl
  30.   add hl,bc
  31.   add hl,hl
  32.  
  33. ; Now add in the digit
  34.   ld e,a
  35.   add hl,de
  36.  
  37. .loop_start
  38.   ld a,(ix)
  39.   sub '0'
  40.   cp 10
  41.   jr c,.loop
  42.   ret
Add Comment
Please, Sign In to add comment