1
\$\begingroup\$

The title pretty much explains it. This is the first program I've written in assembly, so any criticism, either on programming style or saving instructions, would be appreciated.

li $t0, -1
  .data
nl: .asciiz  "\n"
  .text
loop:beq $t0, 100, exit
 add $t0, $t0, 1
 add $a0, $t0, $zero
 li $v0, 1
 syscall
 rem $t1, $t0, 3
 rem $t2, $t0, 5
 or $t3, $t1, $t2 
 beqz $t3, b1
 beqz $t1, b2
 beqz $t2, b3

 la $a0, nl
 li   $v0, 4
 syscall

 j loop

b1:  li $a0, 3
 jal printb
 j loop
b2:  li $a0, 1
 jal printb
 j loop
b3:  li $a0, 2
 jal printb
 j loop

exit:li $v0, 10
 syscall

  .data
fizz: .asciiz  " Fizz\n"
buzz: .asciiz  " Buzz\n"
fizzbuzz: .asciiz  " Fizz Buzz\n"
  .text
printb:
  beq $a0, 1, l1
  beq $a0, 2, l2
  beq $a0, 3, l3
  l1: la $a0, fizz
  j print
  l2: la $a0, buzz
  j print
  l3: la $a0, fizzbuzz
  j print
print:li   $v0, 4
  syscall
  jr $ra
\$\endgroup\$
2
\$\begingroup\$

Given concern for , the obvious change would be to allocate a buffer large enough for all the output data. As you compute each result, just write the results to the output buffer. Then, when you've accumulated it all in the buffer, write the entire buffer to the output in one big chunk.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.