Fix fizzbuzz base pointer clobber
This commit is contained in:
+4
-4
@@ -34,7 +34,7 @@ _test_fizzbuzz:
|
||||
push %rbp
|
||||
mov %rsp, %rbp
|
||||
sub $8, %rsp # Local stack variable to track print case.
|
||||
movq $0, 8(%rsp)
|
||||
movq $0, 0(%rsp)
|
||||
test_fizz:
|
||||
# Retrieve the loop counter to use as the dividend.
|
||||
# It's now 24 bytes up from the stack pointer:
|
||||
@@ -51,7 +51,7 @@ test_fizz:
|
||||
div %rbx
|
||||
cmp $0, %rdx # Was the remainder 0?
|
||||
jne test_buzz # If not, test division by 5.
|
||||
addq $1, 8(%rsp) # Otherwise, increment the print case.
|
||||
addq $1, 0(%rsp) # Otherwise, increment the print case.
|
||||
test_buzz:
|
||||
mov 24(%rsp), %rax # Retrieve the counter again.
|
||||
movq $5, %rbx # Use 5 as the divisor for "buzz" test.
|
||||
@@ -59,9 +59,9 @@ test_buzz:
|
||||
div %rbx
|
||||
cmp $0, %rdx # Was the remainder 0?
|
||||
jne return_print_case # If not, return.
|
||||
addq $2, 8(%rsp) # Otherwise, increment the print case by two.
|
||||
addq $2, 0(%rsp) # Otherwise, increment the print case by two.
|
||||
return_print_case:
|
||||
mov 8(%rsp), %rax # Put the print case in %rax.
|
||||
mov 0(%rsp), %rax # Put the print case in %rax.
|
||||
mov %rbp, %rsp
|
||||
pop %rbp
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user