1

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 ?

John
  • 81
  • 2
  • 12

1 Answers1

0

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

Adam
  • 856
  • 2
  • 9
  • 18
  • thanks for your asnwer @adam. So lets say in my example i want to load each byte from my word. Should i say lb $t0, 4($sp) for the first byte, lb $t1, 3($sp) etc OR lb $t0, 0($sp) for the first, lb $t0, -1($sp) for the second etc – John May 10 '17 at 11:56
  • 1
    when you use `sw` it means you are storing 4 bytes in one memory cell which is word addressable and pointed by the `$sp`. In case you use `lb` than you are dealing with byte-addressable memory which also depends if it's big endian or little endian. – Adam May 10 '17 at 12:07
  • yes i know this lets say we are dealing with big endian. and store a word like my example sw $t0, 0($sp) with $sp=-4. if i want to load the first byte of this word into $t1, what should i do? – John May 10 '17 at 12:13
  • use `lb` with offset of `0` and then the next `lb` should have an offset of `1` – Adam May 10 '17 at 12:21
  • like this lb $t1, 0($sp) => address+sp=0-4=-4? The next one lb $t2, 1($sp) address+sp=1-4=-3 – John May 10 '17 at 12:30
  • 1
    yes that is correct but `$sp` still pointing to a 4 byte word address it doesn't matter when use `lb` – Adam May 10 '17 at 12:44