0
votes

the question revolves around the MIPS assembly.

Let's says in the start of the program the value of the register $sp (stack pointer) is $sp = 0x1000.

Then I write the command: addi $sp, $sp, -12

What will be the value of $sp now?

Will it be 0xFF4? (since 12 in hexadecimal is C and we subtract it from 1000)

Or do i need to multiply 12 by 4 (since 4 byte is the size of word = 32 bit) and then subtract?

1
It counts in bytes, so 0xff4. You can easily check this in a debugger/simulator. Technically $sp is just another general purpose register (it's $29 after all) so it's nothing special. If you write add -12, then that's what is going to happen.Jester
Thanks! After thinking about it as just another register it does seem pretty obviousGabi G

1 Answers

1
votes

addi $sp, $sp, -12 is really no different from addi $t0, $t0, -12 - you are adding -12 to the the value of the register

So if $sp = 0x1000, then the value is 0x1000 - 12 = 0xFF4