Category:68000 Assembly: Difference between revisions

Line 13:
===Address Registers===
There are eight of these as well, numbered A0-A7. A7 is reserved as the stack pointer, and is commonly referenced as SP in assemblers. The others are free to use for any purpose. Although these registers are 32-bit, the 68000's address space is 24-bit (ranges from 0x000000 to 0xFFFFFF), so the leftmost byte is ignored. You can do simple math involving these registers but more complicated commands like multiply or divide can only be used with data registers. Address registers are used to contain addresses and extract the values stored within.
====Loading From Memory====
 
<lang 68000devpac>MOVEA.L #$200000,A2 ;usually these are loaded from a label.
;The hex dump of address $200000: 44 55 66 77
Line 19:
MOVE.B (A2),D0 ;load the byte stored at $200000 into D0. D0 = #$00000044
MOVE.W (A2),D0 ;load the word stored at $200000 into D0. D0 = #$00004455
MOVE.L (A2),D0 ;load the long stored at $200000 into D0. D0 = #$44556677</lang>
MOVE.L D2,(A5) ;store the contents of D2 into the memory address pointed to by A5.</lang>
 
 
====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 .B, 2 for .W, 4 for .L).
<lang 68000devpac>
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
MOVE.L (SP)+,D3 ;pop the top value of the stack into D3</lang>
 
====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
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>
 
===Length===
1,489

edits