Skip to content

Commit fae1832

Browse files
committed
get rid of imul and re-use a 1
1 parent fae19a0 commit fae1832

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

count.asm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ _start: ; argc is at `rsp`, argv is at `rsp + 8`
5757
from_decimal_loop:
5858
movzx rdx, byte [rdi + rcx]
5959
sub rdx, '0'
60-
imul rax, rax, 10
60+
61+
mov rbx, rax
62+
shl rax, 3
63+
shl rbx, 1
64+
add rax, rbx
65+
6166
add rax, rdx
6267
inc rcx
6368
cmp byte [rdi + rcx], 0
@@ -85,7 +90,7 @@ to_decimal_loop:
8590

8691
write: ; args: `rax` syscall, `rdi` fd, `rsi` buf, `rdx` length
8792
mov rax, 1
88-
mov rdi, 1
93+
mov rdi, rax
8994
lea rdx, [output+11]
9095
sub rdx, rsi
9196
syscall

0 commit comments

Comments
 (0)