Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mips_asm/fibonacci.s
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (57 sloc)
2.48 KB
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
# James J | |
.data | |
newl: .asciiz "\n" # var with new line character | |
.text | |
.globl main | |
main: | |
#---------------------start up stuff---------------------------- | |
add $s0, $ra, $zero # save the return address | |
add $t0, $zero, $zero # put zero in t0 | |
addi $t1, $zero, 1 # put one in t1 | |
addi $s1, $zero, 15 # counter limit | |
addi $s2, $zero, 2 # counter var, set to 2 to eliminate an offset | |
#---------------------printing some values------------------------ | |
add $a0, $t0, $zero # print out t0 | |
li $v0, 1 # get ready for int output | |
syscall # | |
la $a0, newl # put new line char in a0 | |
li $v0, 4 # get ready to print string | |
syscall # | |
add $a0, $t1, $zero # print out t1 | |
li $v0, 1 # get ready for int output | |
syscall # | |
la $a0, newl # put new line char in a0 | |
li $v0, 4 # get ready to print string | |
syscall # | |
#-----------------doing some math----------------------- | |
start: | |
beq $s1, $s2, print2 # if counter hits limit jump to print2(print one) | |
addi $s2, $s2, 1 # incriment counter | |
add $t2, $t0, $t1 # t0 + t1 = t2 | |
add $t0, $zero, $t2 # overwrite old t0 value with t2 | |
beq $s1, $s2, print # if counter hits limit jump to print(print both) | |
addi $s2, $s2, 1 # incriment counter | |
add $t2, $t0, $t1 # t0 + t1 = t2 | |
add $t1, $zero, $t2 # overwrite old t1 value with t2 | |
#----------------print more---------------- | |
print: | |
add $a0, $t0, $zero # print out t0 | |
li $v0, 1 # get ready for int output | |
syscall # | |
la $a0, newl # put new line char in a0 | |
li $v0, 4 # get ready to print string | |
syscall # | |
beq $s1, $s2, end # check if (counter == counter_limit){end();} | |
print2: | |
add $a0, $t1, $zero # print out t1 | |
li $v0, 1 # get ready for int output | |
syscall # | |
la $a0, newl # put new line char in a0 | |
li $v0, 4 # get ready to print string | |
syscall # | |
beq $s1, $s2, end # check if (counter == counter_limit){end();} | |
j start # jump back to start (looping) | |
end: | |
move $s0, $ra # restore return address | |
li $v0, 10 # get ready to exit | |
syscall # |