-1

I'm trying to understand the first microcorruption challenge.

I want to ask about the first line of the main function.

Why would they add that address to the stack pointer?

microcorruption

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
haruhi
  • 177
  • 1
  • 13

1 Answers1

4

This looks like a 16-bit ISA1, otherwise the disassembly makes no sense.

0xff9c is -100 in 16-bit 2's complement, so it looks like this is reserving 100 bytes of stack space for main to use. (Stacks grow downward on most machines). It's not an address, just a small offset.

See MSP430 Assembly Stack Pointer Behavior for a detailed example of MSP430 stack layout and usage.


Footnote 1: MSP430 possibly? http://mspgcc.sourceforge.net/manual/x82.html it's a 16-bit ISA with those register names, and those mnemonics, and I think its machine code uses variable-length 2 or 4 byte instructions.

It's definitely not ARM; call and jmp are not ARM mnemonics; that would be bl and b. Also, ARM uses op dst, src1, src2 syntax, while this disassembly uses op src, dst.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thank you. The manual of this challenge also said that it was MSP430. Sorry I should have mentioned it... But I want to ask why it's -100 and not 100? – haruhi Jan 10 '20 at 21:34
  • 2
    @haruhi: because it's being used with an `add` instruction, not `sub`. To move SP downward, you have to add a negative number. Or do you mean why does `0xff9c` represent -100 instead of +100? See https://en.wikipedia.org/wiki/Two%27s_complement. If you mean why does the stack grow down: [Why does the stack grow downward?](//softwareengineering.stackexchange.com/q/137640). And yes you definitely should have mentioned what ISA you were asking about. – Peter Cordes Jan 10 '20 at 21:42