Last active
June 13, 2018 05:29
-
-
Save danthedaniel/8cfcf9012756bf18dbd61eb44d45dcb2 to your computer and use it in GitHub Desktop.
FizzBuzz in 32-bit MIPS Assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
fizz: .asciiz "Fizz" | |
buzz: .asciiz "Buzz" | |
line: .asciiz "\n" | |
.text | |
main: | |
li $t0,0 | |
li $t1,101 | |
li $t2,3 | |
li $t3,5 | |
li $t5,0 | |
loop: | |
# $t0 % 3 | |
div $t0,$t2 | |
mfhi $t4 | |
# != 0: goto check5 | |
bgtz $t4,check5 | |
# set matched flag | |
li $t5,1 | |
# print "Fizz" | |
li $v0,4 | |
la $a0,fizz | |
syscall | |
check5: | |
# t0 % 5 | |
div $t0,$t3 | |
mfhi $t4 | |
# != 0: goto checkneither | |
bgtz $t4,checkneither | |
# set matched flag | |
li $t5,1 | |
# print "Buzz" | |
li $v0,4 | |
la $a0,buzz | |
syscall | |
checkneither: | |
# check if we've matched yet | |
bgtz $t5,newline | |
# print i | |
li $v0,1 | |
ori $a0,$t0,0 | |
syscall | |
newline: | |
# print "\n" | |
li $v0,4 | |
la $a0,line | |
syscall | |
# Exit if our iteration variable == 101 | |
li $t5,0 | |
addi $t0,$t0,1 | |
bne $t0,$t1,loop | |
exit: | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment