From 163f74bc0c70d97eba2df879a7f15824cacacaa9 Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 22 Oct 2026 14:25:24 +0000 Subject: [PATCH] Fix fizzbuzz base pointer clobber --- fizzbuzz/fizzbuzz.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fizzbuzz/fizzbuzz.s b/fizzbuzz/fizzbuzz.s index 9d866db..5263a9f 100644 --- a/fizzbuzz/fizzbuzz.s +++ b/fizzbuzz/fizzbuzz.s @@ -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