Pointers and references: Difference between revisions

(68000 Assembly)
Line 5:
In most assemblers, a line of code or a value in work RAM can be given a label.
 
<lang 68000devpac> myVar equ $100000 ; a section of user ram given a label
myData: ; a data table given a label
dc.b $80,$81,$82,$83</lang>
Line 23:
 
Putting a + after (A0) auto-increments the pointer by 1,2,or 4 for MOVE.B, MOVE.W, and MOVE.L respectively. The increment happens after the move.
 
<lang 68000devpac>LEA myData,A0 ;Assume for this example that data registers all equal 0.
MOVE.B (A0)+,D0 ;D0 = 00000080
MOVE.B (A0)+,D1 ;D1 = 00000081
MOVE.B (A0)+,D2 ;D2 = 00000082</lang>
 
 
Putting a - before (A0) pre-decrements the pointer by 1,2, or 4 for MOVE.B, MOVE.W, and MOVE.L respectively, before the move takes place.
<lang 68000devpac>LEA myData+4,A0 ;Assume for this example that data registers all equal 0.
MOVE.B -(A0),D0 ;D0 = 00000083
MOVE.B -(A0),D1 ;D1 = 00000082
MOVE.B -(A0),D2 ;D2 = 00000081</lang>
 
LEA can also be used to pre-calculate a complex offset to an address.
<lang 68000devpac>LEA myData,A0
MOVE.W #$0C,D0
LEA (4,A0,D0),A3</lang>
 
An address can be offset by an immediate value, a register, or both. Data register offsets are measured at 16 bit word length. Although the second LEA is in brackets, it does NOT dereference the pointer. If A0 is the address where a pointer is stored, you will need to use MOVE.L instead of LEA.
 
===References===
1,489

edits