Slight speedup in itoa

This commit is contained in:
Bill Rossi 2023-12-21 09:49:14 -05:00
parent d45f882710
commit ffface8b0a

View File

@ -1,13 +1,7 @@
;; rax contains the integer ;; rax contains the integer
;; rbx contains a pointer to the string buffer ;; rbx contains a pointer to the string buffer
itoa: itoa:
;; Fill 6 digits with zeroes
mov byte [rbx], '0' mov byte [rbx], '0'
mov byte [rbx + 1], '0'
mov byte [rbx + 2], '0'
mov byte [rbx + 3], '0'
mov byte [rbx + 4], '0'
mov byte [rbx + 5], '0'
;; Special case for the number '0' ;; Special case for the number '0'
cmp rax, 0 cmp rax, 0
@ -16,6 +10,13 @@ itoa:
ret ret
.not_zero: .not_zero:
;; Fill 6 digits with zeroes
mov byte [rbx + 1], '0'
mov byte [rbx + 2], '0'
mov byte [rbx + 3], '0'
mov byte [rbx + 4], '0'
mov byte [rbx + 5], '0'
sub rax, 100000 sub rax, 100000
inc byte [rbx] inc byte [rbx]
cmp rax, 0 cmp rax, 0