Add fizzbuzz operand size suffixes
This commit is contained in:
+6
-6
@@ -51,7 +51,7 @@ test_fizz:
|
|||||||
div %rbx
|
div %rbx
|
||||||
cmp $0, %rdx # Was the remainder 0?
|
cmp $0, %rdx # Was the remainder 0?
|
||||||
jne test_buzz # If not, test division by 5.
|
jne test_buzz # If not, test division by 5.
|
||||||
add $1, 8(%rsp) # Otherwise, increment the print case.
|
addq $1, 8(%rsp) # Otherwise, increment the print case.
|
||||||
test_buzz:
|
test_buzz:
|
||||||
mov 24(%rsp), %rax # Retrieve the counter again.
|
mov 24(%rsp), %rax # Retrieve the counter again.
|
||||||
movq $5, %rbx # Use 5 as the divisor for "buzz" test.
|
movq $5, %rbx # Use 5 as the divisor for "buzz" test.
|
||||||
@@ -59,7 +59,7 @@ test_buzz:
|
|||||||
div %rbx
|
div %rbx
|
||||||
cmp $0, %rdx # Was the remainder 0?
|
cmp $0, %rdx # Was the remainder 0?
|
||||||
jne return_print_case # If not, return.
|
jne return_print_case # If not, return.
|
||||||
add $2, 8(%rsp) # Otherwise, increment the print case by two.
|
addq $2, 8(%rsp) # Otherwise, increment the print case by two.
|
||||||
return_print_case:
|
return_print_case:
|
||||||
mov 8(%rsp), %rax # Put the print case in %rax.
|
mov 8(%rsp), %rax # Put the print case in %rax.
|
||||||
mov %rbp, %rsp
|
mov %rbp, %rsp
|
||||||
@@ -136,13 +136,13 @@ _print:
|
|||||||
# %rcx will hold the address of the buffer to be printed.
|
# %rcx will hold the address of the buffer to be printed.
|
||||||
# %rdx will hold the number of bytes to write.
|
# %rdx will hold the number of bytes to write.
|
||||||
# How these are set depends on the print case:
|
# How these are set depends on the print case:
|
||||||
cmp $0, 16(%rsp)
|
cmpq $0, 16(%rsp)
|
||||||
je print_counter
|
je print_counter
|
||||||
cmp $1, 16(%rsp)
|
cmpq $1, 16(%rsp)
|
||||||
je print_fizz
|
je print_fizz
|
||||||
cmp $2, 16(%rsp)
|
cmpq $2, 16(%rsp)
|
||||||
je print_buzz
|
je print_buzz
|
||||||
cmp $3, 16(%rsp)
|
cmpq $3, 16(%rsp)
|
||||||
je print_fizzbuzz
|
je print_fizzbuzz
|
||||||
print_counter:
|
print_counter:
|
||||||
# We need to convert the counter to ASCII.
|
# We need to convert the counter to ASCII.
|
||||||
|
|||||||
Reference in New Issue
Block a user