This repository has been archived on 2021-01-14. You can view files and clone it, but cannot push or open issues or pull requests.
xed/lib/___uitobcd.s
2020-09-19 22:16:34 +02:00

58 lines
675 B
ArmAsm

#code _CODE
; void __uitobcd (unsigned int v, unsigned char bcd[3])
; __uitobcd converts v to BCD representation to the bcd.
; bcd[] will contain BCD value.
;
___uitobcd:
push ix
ld ix, #0
add ix, sp
;
ld bc, #0x1000
ld d, c
ld e, c
ld l, 4 (ix)
ld h, 5 (ix)
;
;--- begin speed optimization
;
ld a, h
or a, a
jr NZ, 100$
;
ld h, l
srl b
;
;--- end speed optimization
;
; HL - binary value
; CDE - future BCD value
; B - bits count (16)
100$:
add hl, hl
ld a, e
adc a, a
daa
ld e, a
ld a, d
adc a, a
daa
ld d, a
ld a, c
adc a, a
daa
ld c, a
djnz 100$
;
ld l, 6 (ix)
ld h, 7 (ix)
ld (hl), e
inc hl
ld (hl), d
inc hl
ld (hl), c
;
pop ix
ret