Skip to content

Instantly share code, notes, and snippets.

@gitpraetorianlabs
Created June 1, 2016 22:44
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 gitpraetorianlabs/f35ba5a7ff5609729a3a986f199e39d3 to your computer and use it in GitHub Desktop.
Save gitpraetorianlabs/f35ba5a7ff5609729a3a986f199e39d3 to your computer and use it in GitHub Desktop.
=-------------------------------=
| [0x4003b0] |
| main: |
| (fcn) sym.main 188 |
| addiu sp, sp, -0x60 |
| sw ra, 0x5c(sp) |
| sw fp, 0x58(sp) |
| move fp, sp |
| sw zero, 0x30(fp) | // Initialize int a to 0
| addiu v0, zero, 1 | // Perform (0+1) and store the unsigned result in register $v0
| sw v0, 0x34(fp) | // Store $v0 at this offset (int b = 1)
| addiu v0, zero, 2 | // Perform (0+2) and store the unsigned result in register $v0
| sw v0, 0x38(fp) | // Store $v0 at this offset (int c = 2)
| addiu v0, zero, 3 | // Perform (0+3) and store the unsigned result in register $v0
| sw v0, 0x3c(fp) | // Store $v0 at this offset (int d = 3)
| addiu v0, zero, 4 | // Perform (0+4) and store the unsigned result in register $v0
| sw v0, 0x40(fp) | // Store $v0 at this offset (int e = 4)
| addiu v0, zero, 5 | // Perform (0+5) and store the unsigned result in register $v0
| sw v0, 0x44(fp) | // Store $v0 at this offset (int f = 5)
| addiu v0, zero, 6 | // Perform (0+6) and store the unsigned result in register $v0
| sw v0, 0x48(fp) | // Store $v0 at this offset (int g = 6)
| addiu v0, zero, 7 | // Perform (0+7) and store the unsigned result in register $v0
| sw v0, 0x4c(fp) | // Store $v0 at this offset (int h = 7)
| addiu v0, zero, 8 | // Perform (0+8) and store the unsigned result in register $v0
| sw v0, 0x50(fp) | // Store $v0 at this offset (int i = 8)
| addiu v0, zero, 9 | // Perform (0+9) and store the unsigned result in register $v0
| sw v0, 0x54(fp) | // Store $v0 at this offset (int j = 9)
| lw v0, 0x40(fp) | /*
| sw v0, 0x10(sp) |
| lw v0, 0x44(fp) |
| sw v0, 0x14(sp) |
| lw v0, 0x48(fp) |
| sw v0, 0x18(sp) | This is all for passing the arguments for the function call but on the stack
| lw v0, 0x4c(fp) | (Variables int e ... int j)
| sw v0, 0x1c(sp) |
| lw v0, 0x50(fp) |
| sw v0, 0x20(sp) |
| lw v0, 0x54(fp) |
| sw v0, 0x24(sp) | */
| lw a0, 0x30(fp) | // Store local variable (int a) into register $a0 ($a0 = 0)
| lw a1, 0x34(fp) | // Store local variable (int b) into register $a0 ($a0 = 1)
| lw a2, 0x38(fp) | // Store local variable (int c) into register $a0 ($a0 = 2)
| lw a3, 0x3c(fp) | // Store local variable (int d) into register $a0 ($a0 = 3)
| jal sym.pass_args_to_me ;[a] | // Call function pass_args_to_me and store $PC+8 into register $ra
| nop | // No instruction performed before the call
| move sp, fp | // Function Exit. Store Address of the Frame Pointer into the Stack Pointer register ($sp)
| lw ra, 0x5c(sp) | // Restore the saved return address from the stack and load it into $ra
| lw fp, 0x58(sp) | // Restore the saved frame pointer address from the stack and load it into $fp (aka $s8)
| addiu sp, sp, 0x60 | // Restore stack offset adjustment
| jr ra | // Jump to the address in $ra
| nop | // No instruction to perform before the jump
=-------------------------------=
@sferrini
Copy link

In the comments from line 41 to line 43 the register still $a0, should instead reflect the actual register.
I guess it's just a copy and paste oversight.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment