1

enter image description here

This is a diagram in a class of mine and only instruction 0 has executed. In the stack on the lower right of that digram, it stores $ra at an address 4 less than the $sp which is at 128.

In my book, however, they use offsets to mean higher than the $sp. here are the diagrams:

enter image description here

and

enter image description here

What’s strange to me is that in the first image, the lw and sw offsets are positive numbers but cause the values to be stored negative to the $sp at lower addresses.

However, the last two images use offsets to store or load values at higher addresses relative to $sp. The book makes room by subtracting from the $sp first and then storing register values in the freed up stack using positive offset numbers which go to higher addresses.

Are these two inconsistent?

Jwan622
  • 11,015
  • 21
  • 88
  • 181
  • 1
    The first diagram is simply wrong. `$sp` is at 128 and 128 + 4 is 132, which is where `$ra` should be stored if the first instruction executed. "What’s strange to me is that in the first image, the lw and sw offsets are positive numbers but cause the values to be stored negative to the $sp at lower addresses." The diagram is incorrect. – Erik Eidt Oct 10 '19 at 20:35
  • Possible duplicate of [Does sw and lw in MIPS store a value below or above the stack pointer?](https://stackoverflow.com/questions/58325075/does-sw-and-lw-in-mips-store-a-value-below-or-above-the-stack-pointer) – Raymond Chen Nov 03 '19 at 22:57

0 Answers0