2

Why is MIPS stack base 0x7ffffffc rather than 0x80000000?

If I understand correctly, the stack pointer refers to the last item placed on the stack. So, if that's the case, doesn't that mean that address 0x7ffffffc never gets used because the conventional way to push an integer on the stack would be do decrement $sp to 0x7ffffff8 and place the pushed value there?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zack
  • 6,232
  • 8
  • 38
  • 68
  • isnt push and pop pseudo code and how this works would depend on that pseudocode for your assembler (the specific tool), yes? – old_timer Nov 02 '20 at 20:59
  • size minus 4 would be a safer bet if you dont know going in what your tools are doing... – old_timer Nov 02 '20 at 21:00
  • You are right: It would depend on what the tools do; but, it appears that most (if not all) textbooks consistently say that the stack pointer points to the last item placed on the stack. If that is some sort of convention, I would expect the tools to follow it. – Zack Nov 03 '20 at 00:08
  • 1
    yeah so you could start with 0x800....but that doesnt mean most folks do that, some dont take the time and simply use the minus 4 or 8 which generally works and is safe and they dont have to think about it again and if 4 or 8 breaks your memory budget you have other problems. – old_timer Nov 03 '20 at 00:17

1 Answers1

2

The simulators (i.e. QtSPIM) do weird things with the stack pointer; they take action — such as to allocate additional memory for the stack — when the stack pointer is modified, rather than when the stack memory is stored into.  (As a result, you can give these simulators severe grief by putting a random value in the stack pointer register.)

My guess then is that since 0x80000000 is in protected kernel memory, they don't want that value in the register at all, and yes, this then means that a word of memory is never used.

I would venture that the actual hardware would not have this issue.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53