0

I am aware of pushing a stack pointer but I am not sure of how to push all of the elements.

This is how I defined a stack pointer.

addi $sp, $sp, -24
sw $ra, 0($sp)
sw $s0, 4($sp) 
sw $s1, 8($sp) 
sw $s7, 12($sp) 
sw $s3, 16($sp) 
sw $s4, 20($sp) 

How can I push and remove them? Do I just

addi $sp, $sp, 24

Or loop for 6 times? Thank you for helping in advance.

  • 2
    Yes, `addi $sp, $sp, 24` would move the stack pointer back to where it was before the subtraction. Note that this doesn't actually remove any data from the stack, but that doesn't matter unless you're dealing with sensitive data that needs to be overwritten. – Michael Nov 30 '20 at 12:59
  • 2
    You didn't use a loop to push, why would you look to a loop to pop? – Erik Eidt Nov 30 '20 at 16:23
  • @Michael: Unless your ABI has a red-zone, you have to consider anything below `$sp` as potentially stepped on by interrupt / signal handlers. It's not wrong to say it "removes" them from the in-use part of the stack; referencing them after this would be a sort of use-after-free bug. But yeah, no need to zero out the memory as you pop. – Peter Cordes Nov 30 '20 at 20:31

0 Answers0