Created
April 18, 2012 20:29
-
-
Save ryan-beckett/2416339 to your computer and use it in GitHub Desktop.
MIPS assembly: demonstrates the use of the stack for sending function arguments.
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
.text | |
main: | |
#populate arg registers | |
li $a0, 1 | |
li $a1, 2 | |
li $a2, 3 | |
li $a3, 4 | |
#push 5th arg on stack | |
li $t0, 10 | |
sw $t0, 0($sp) | |
subi $sp, $sp, 4 | |
jal printf | |
jal exit | |
printf: | |
#load 5th arg from stack | |
addi $sp, $sp, 4 | |
lw $t0, 0($sp) | |
move $a0, $t0 | |
li $v0, 1 | |
syscall | |
jr $ra | |
exit: | |
li $v0, 10 | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment