Fix fizzbuzz output length
This commit is contained in:
+7
-5
@@ -110,9 +110,10 @@ save_to_buffer_loop:
|
|||||||
cmp $0, %rcx # Have we processed all digits?
|
cmp $0, %rcx # Have we processed all digits?
|
||||||
jne save_to_buffer_loop # If not, loop again.
|
jne save_to_buffer_loop # If not, loop again.
|
||||||
# We're done moving data from the stack to the buffer.
|
# 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.
|
# 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
|
mov %rbp, %rsp
|
||||||
pop %rbp
|
pop %rbp
|
||||||
ret
|
ret
|
||||||
@@ -159,9 +160,10 @@ print_counter:
|
|||||||
mov $4, %rax
|
mov $4, %rax
|
||||||
mov $1, %rbx
|
mov $1, %rbx
|
||||||
mov $number_string, %rcx # Set the buffer the kernel should use.
|
mov $number_string, %rcx # Set the buffer the kernel should use.
|
||||||
# Print 3 digits + 1 newline = 4 bytes.
|
# _itoa leaves %rdx pointing at the newline after the digits.
|
||||||
# FIX: this is wrong -- we're not always printing 4 bytes.
|
# Length = (newline address - buffer start) + 1 for the newline.
|
||||||
mov $4, %rdx
|
sub $number_string, %rdx
|
||||||
|
inc %rdx
|
||||||
jmp print_and_return
|
jmp print_and_return
|
||||||
print_fizz:
|
print_fizz:
|
||||||
mov $fizz, %rcx
|
mov $fizz, %rcx
|
||||||
|
|||||||
Reference in New Issue
Block a user