2021-07-04 20:35:27 +00:00
|
|
|
; IN:
|
|
|
|
; ax = number to convert
|
2021-07-04 20:40:39 +00:00
|
|
|
; ds:bx = storage buffer
|
2021-07-04 20:35:27 +00:00
|
|
|
; OUT:
|
2021-07-04 20:40:39 +00:00
|
|
|
; ds:bx = start of converted number
|
2021-07-04 20:35:27 +00:00
|
|
|
itoa:
|
|
|
|
push ax
|
|
|
|
push cx
|
|
|
|
push dx
|
|
|
|
|
|
|
|
mov cx, 10
|
|
|
|
|
|
|
|
add bx, 5
|
2021-07-04 20:40:39 +00:00
|
|
|
mov byte [bx], 0
|
2021-07-04 20:35:27 +00:00
|
|
|
|
|
|
|
.convert_loop:
|
|
|
|
test ax, ax
|
|
|
|
jz .end
|
|
|
|
|
|
|
|
xor dx, dx
|
|
|
|
div cx
|
|
|
|
|
|
|
|
add dl, '0'
|
|
|
|
dec bx
|
2021-07-04 20:40:39 +00:00
|
|
|
mov byte [bx], dl
|
2021-07-04 20:35:27 +00:00
|
|
|
|
|
|
|
jmp .convert_loop
|
|
|
|
|
|
|
|
.end:
|
|
|
|
pop dx
|
|
|
|
pop cx
|
|
|
|
pop ax
|
|
|
|
ret
|