Skip to content

Instantly share code, notes, and snippets.

@ryan-beckett
Created April 18, 2012 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-beckett/2416339 to your computer and use it in GitHub Desktop.
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.
.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