Created
May 5, 2014 09:43
-
-
Save voter101/b5c14b1bc12828d575d9 to your computer and use it in GitHub Desktop.
Mips exercise 1
This file contains hidden or 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
jal printResult | |
j main | |
nextState: | |
add $t7, $zero, $ra | |
addi $t6, $zero, 0 | |
addi $t4, $zero, 31 | |
nextStateLoop: | |
jal countNeighbours | |
jal checkBit | |
beqz $t0, nextStateLoopDead | |
nextStateLoopAlive: | |
jal aliveCell | |
j nextStateNextIter | |
nextStateLoopDead: | |
jal deadCell | |
nextStateNextIter: | |
addi $t4, $t4, -1 | |
bltz $t4, nextStateReturn | |
j nextStateLoop | |
nextStateReturn: | |
addi $v0, $t6, 0 | |
jr $t7 | |
countNeighbours: | |
addi $t5, $zero, 0 | |
add $t3, $zero, $ra | |
addi $a1, $t4, -2 | |
blt $a1, $zero, NM1 | |
jal addBit | |
NM1: | |
addi $a1, $t4, -1 | |
blt $a1, $zero, NP1 | |
jal addBit | |
NP1: | |
addi $a1, $t4, 1 | |
addi $t1, $zero, 31 | |
bgt $a1, $t1, NP2 | |
jal addBit | |
NP2: | |
addi $a1, $t4, 2 | |
addi $t1, $zero, 31 | |
bgt $a1, $t1, returnCountNeighbours | |
jal addBit | |
returnCountNeighbours: | |
jr $t3 | |
addBit: | |
addi $t2, $zero, 1 | |
sllv $t0, $t2, $a1 | |
and $t0, $a0, $t0 | |
slt $t0, $zero, $t0 | |
add $t5, $t5, $t0 | |
jr $ra | |
checkBit: | |
addi $t1, $zero, 1 | |
sllv $t0, $t1, $a1 | |
and $t0, $a0, $t0 | |
slt $t0, $zero, $t0 | |
jr $ra | |
aliveCell: | |
add $t3, $zero, $ra | |
addi $t1, $zero, 2 | |
beq $t1, $t5, endAliveCell | |
addi $t1, $zero, 4 | |
beq $t1, $t5, endAliveCell | |
jal makeAlive | |
j endAliveCell | |
endAliveCell: | |
jr $t3 | |
deadCell: | |
add $t3, $zero, $ra | |
addi $t1, $zero, 2 | |
beq $t1, $t5, deadCellAlive | |
addi $t1, $zero, 3 | |
beq $t1, $t5 deadCellAlive | |
j endDeadCell | |
deadCellAlive: | |
jal makeAlive | |
endDeadCell: | |
jr $t3 | |
makeAlive: | |
addi $t0, $zero, 1 | |
sllv $t0, $t0, $t4 | |
or $t6, $t0, $t6 | |
jr $ra | |
printResult: | |
add $t7, $zero, $ra | |
addi $t2, $zero, 31 | |
printLoop: | |
add $a1, $zero, $t2 | |
jal checkBit | |
li $v0, 1 | |
add $a2, $zero, $a0 | |
add $a0, $zero, $t0 | |
syscall | |
add $a0, $zero, $a2 | |
addi $t2, $t2, -1 | |
bltz $t2, printResultReturn | |
j printLoop | |
printResultReturn: | |
add $a2, $zero, $a0 | |
addi $v0, $zero, 4 | |
la $a0, newLine | |
syscall | |
add $a0, $zero, $a2 | |
jr $t7 | |
main: | |
jal nextState | |
add $a0, $zero, $v0 | |
jal printResult | |
j main | |
.data | |
newLine: .asciiz "\n" | |
.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment