Last active
March 31, 2018 22:28
-
-
Save fellipecaetano/8970d6d5222d9b7c87f500670a407757 to your computer and use it in GitHub Desktop.
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
.text | |
.globl main | |
main: | |
addi $a0, $zero, 7 | |
jal rot | |
j exit | |
rot: | |
# Check if $a0 < 2 | |
slti $t0, $a0, 2 | |
bne $t0, $zero, rot_return_0 | |
# Check if $a0 == 2 | |
addi $t0, $zero, 2 | |
beq $t0, $a0, rot_return_1 | |
# Preserve original argument and return address | |
addi $sp, $sp, -8 | |
sw $a0, 0($sp) | |
sw $ra, 4($sp) | |
# $v0 = 1 + rot($a0 - 2) | |
addi $a0, $a0, -2 | |
jal rot | |
addi $v0, $v0, 1 | |
# Restore original argument and return address | |
lw $a0, 0($sp) | |
lw $ra, 4($sp) | |
addi $sp, $sp, 8 | |
# return $v0 | |
jr $ra | |
rot_return_0: | |
addi $v0, $zero, 0 | |
jr $ra | |
rot_return_1: | |
addi $v0, $zero, 1 | |
jr $ra | |
exit: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ficou bem parecido com o meu, só mudou o fato de eu já entrar empilhando e sempre desempilhar no fim. Se liga: