mipsmips32mips64

"Memory limits" using sw in mips


Lets say i have the following command in MIPS:

sw $t0, 0($sp) # $sp=-4

Does that mean that the register $t0 is saved from 0 to -3 byte or from -4 to -7 byte ?


Solution

  • Stack growing downward in memory to make space for new data to be saved. The stack pointer $sp point to the top of stack.

    The stack pointer $sp starts at a high memory address and decrements to expand as needed. Figure (b) shows the stack expanding to allow two more data words of temporary storage. To do so, $sp decrements by 8 to become 0x7FFFFFF4. Two additional data words, 0xAABBCCDD and 0x11223344, are temporarily stored on the stack.

    So in your case if I understand your question well the sw is word- addressable and the word will be stored on that location in memory which $sp point to. In case you store the next word it must have an offset of 4. [Harris&Harris]

    stack

    UPDATE

    Take this example when you use lb Say you have this word 0x23456789

    when using lb $s0,1($0) After the load byte instruction, lb $s0, 1($0), $s0 would contain 0x00000045 on a big-endian system and 0x00000067 on a little-endian system.[Harris&Harris]

    bigendian