Category:68000 Assembly: Difference between revisions

Content deleted Content added
Puppydrum64 (talk | contribs)
Puppydrum64 (talk | contribs)
Line 113: Line 113:
====The Stack====
====The Stack====
The 68000's stack is commonly referred to as <code>SP</code> but it is also address register <code>A7</code>. This register is handled differently than the other address registers when pushing bytes onto the stack. A byte value pushed onto the stack will be padded to the <b>right</b>. The stack needs to pad byte-length data so that it can stay word-aligned at all times. Otherwise the CPU would crash as soon as you tried to use the stack for anything other than a byte!
The 68000's stack is commonly referred to as <code>SP</code> but it is also address register <code>A7</code>. This register is handled differently than the other address registers when pushing bytes onto the stack. A byte value pushed onto the stack will be padded to the <b>right</b>. The stack needs to pad byte-length data so that it can stay word-aligned at all times. Otherwise the CPU would crash as soon as you tried to use the stack for anything other than a byte!


You can abuse this property of the stack to quickly swap bytes around. Suppose you had a number like <code>#$11223344</code> stored in <code>D0</code> and you wanted to change it to <code>#$11224433</code>:

<lang 68000devpac>MOVE.W D0,-(SP) ;push #$3344 onto the stack
ROL.W #8,D0
MOVE.B (SP)+,D0 ;pop them in the order #$44 #$33.</lang>


===Length===
===Length===