Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; This is intended for the eZ80, not the Z80 (it will work, just not as efficiently, and only for 16 bits).
- ; For a Z80 version, see https://github.com/Zeda/Z80-Optimized-Routines/blob/master/conversion/uitoa_16.z80
- ;
- ; This expects to be called in ADL mode.
- atou24:
- ;Inputs:
- ; IX points to the base-10 string
- ;Outputs:
- ; IX points to the first non-digit byte
- ; HL is the 24-bit number
- ; Note that if the input exceeds 24 bits, input%2^24 is returned
- ;Destroys:
- ; AF, BC, DE
- ;
- ;Set HL and DE to 0
- or a
- sbc hl,hl
- ex de,hl
- sbc hl,hl
- jr .loop_start
- .loop:
- inc ix
- ; multiply HL by 10
- push hl
- pop bc
- add hl,hl
- add hl,hl
- add hl,bc
- add hl,hl
- ; Now add in the digit
- ld e,a
- add hl,de
- .loop_start
- ld a,(ix)
- sub '0'
- cp 10
- jr c,.loop
- ret
Add Comment
Please, Sign In to add comment