Fix fizzbuzz output length

This commit is contained in:
dwrz
2026-10-22 14:38:55 +00:00
parent 163f74bc0c
commit 30f2ccddda
+7 -5
View File
@@ -110,9 +110,10 @@ save_to_buffer_loop:
cmp $0, %rcx # Have we processed all digits?
jne save_to_buffer_loop # If not, loop again.
# We're done moving data from the stack to the buffer.
# Let's add a newline to the end of our digits.
# Let's add a newline right after our digits.
# The ASCII integer representation of "\n" is 10.
movb $10, number_string + 3
# %rdx is left pointing at the newline, so callers can compute length.
movb $10, (%rdx)
mov %rbp, %rsp
pop %rbp
ret
@@ -159,9 +160,10 @@ print_counter:
mov $4, %rax
mov $1, %rbx
mov $number_string, %rcx # Set the buffer the kernel should use.
# Print 3 digits + 1 newline = 4 bytes.
# FIX: this is wrong -- we're not always printing 4 bytes.
mov $4, %rdx
# _itoa leaves %rdx pointing at the newline after the digits.
# Length = (newline address - buffer start) + 1 for the newline.
sub $number_string, %rdx
inc %rdx
jmp print_and_return
print_fizz:
mov $fizz, %rcx