Category:68000 Assembly: Difference between revisions

(added notes about Big-Endian)
Line 42:
 
====Post-Increment====
The post-increment mode is specified by adding a + to the end of parentheses. This means that after the command is done, the address stored in the <b>address register</b> (not the value stored at that address) is increased by the byte length of the command (1 for <code>.B</code>, 2 for <code>.W</code>, 4 for <code>.L</code>).
<lang 68000devpac>MOVEA.L #$00240000,A4 ;load the address $240000 into A4
MOVEA.L #$00240000,A4 ;load the address $240000 into A4
MOVE.W (A4)+,D0 ;move the word stored at $240000 into D0, then increment to #$240002
MOVE.L (A4)+,D1 ;move the long stored at $240000 into D1, then increment to #$240006
Line 51 ⟶ 50:
====Pre-Decrement====
The pre-decrement mode is specified by typing a - before the parentheses. This means that before the command is done, the address stored in the address register is decreased by the byte length of the command.
<lang 68000devpac>MOVEA.L #$0024000A,A4 ;load the address $24000A into A4
MOVEA.L #$0024000A,A4 ;load the address $24000A into A4
MOVE.W -(A4),D0 ;move the word stored at $240008 into D0
MOVE.L -(A4),D1 ;move the long stored at $240004 into D1
MOVE.L D2,-(SP) ;push the contents of D2 onto the stack</lang>
 
====Address Offsets====
A memory address can be offset by a data register, an immediate value, or both. If a data register is used, only the bottom 2 bytes are considered. In either case, the contents of the data register and/or the immediate value are added to the value stored in the address register, and the value is read from that address at the specified length. The offsets are applied during the calculation only; the actual contents in the address register after the move are unchanged. Using a post-increment or pre-decrement with this addressing mode will only update the address by the specified length, not by the offsets.
 
<lang 68000devpac>MOVE.B (4,A0,D0),D1 ;The byte at A0+D0+4 is loaded into D1.</lang>
It's possible to use the same data register as the offset and the destination. This does not cause any problems whatsoever, as the data register offset is "locked in" before the move, and is only updated after the command fully executes. Using the same command again immediately afterwards will offset based on the new value of that register.
 
<lang 68000devpac>MOVE.W (6,A0,D0),D0 ;The word at A0+D0+6 is read, then loaded into D0.</lang>
A very important note is that when using this method with words and longs, the resulting address <b><i>must be even</i></b> Otherwise the CPU will crash. For <code>MOVE.B</code> it doesn't matter.
 
===Length===
1,489

edits