Category:68000 Assembly: Difference between revisions

m
→‎Alignment: Provided an example of a "dummy read"
No edit summary
m (→‎Alignment: Provided an example of a "dummy read")
Line 173:
DC.W $1000,$2000,$3000,$4000</lang>
 
Another way is to pad the data with an extra byte, so that there is an even number of entries in the table. This allows the programmer to do a "dummy read" (i.e. reading with post-increment with the sole purpose of incrementing the pointer, with the value read being of zero interest.) This becomes impractical with large data tables, so the <code>EVEN</code> directive can be placed after a series of bytes. If the byte count is odd, <code>EVEN</code> will pad the data with an extra byte. If it's already even, the <code>EVEN</code> command is ignored. This saves you the trouble of having to count a long series of bytes without worrying about wasting space.
 
<lang 68000devpac>MyString: DC.B "HELLO WORLD 12345678900000",0
EVEN ;some assemblers require this to be on its own line</lang>
 
A third way is to perform a "dummy read." This is when a value is read from an address using pre-decrement or post-increment, with the sole purpose of moving the pointer, and the value being read is of zero interest. This method lets you work with mixed data types in the same table, but it requires the programmer to know in advance where the byte-length data begins and ends.
<lang 68000devpac>TestData:
DC.B $02,$03,$04
DC.W $0345
 
LEA TestData,A0 ;load effective address of TestData into A0.
MOVE.B (A0)+,(A1)+ ;copy $02 to a new memory location
MOVE.B (A0)+,(A1)+ ;copy $03 to a new memory location
MOVE.B (A0)+,(A1)+ ;copy $04 to a new memory location
;if we did MOVE.W (A0)+,(A1)+ now we'd crash. First we need to adjust the pointers.
MOVE.B (A0)+,D7 ;dummy read to D7. Now A0 is word aligned.
MOVE.B (A1)+,D7 ;dummy read to D7. Now A0 is word aligned.
MOVE.W (A0)+,(A1)+ ;copy $0345 to a new memory location</lang>
 
Using <code>ADDA.L #1,A0</code> and <code>ADDA.L #1,A1</code> would have worked also, instead of the dummy read. The 68000 gives the programmer a lot of different ways to do a task.
 
==Subroutines==
Subroutines work exactly the same as they do in [[6502 Assembly]]. Even the commands are the same; <code>JSR</code> and <code>RTS</code>. The only difference is that return spoofing doesn't require the return address to be decremented by 1. The 68000 also adds <code>BSR</code> for nearby subroutines. These still need to end in an <code>RTS</code> just the same, but saves CPU cycles compared to a <code>JSR</code>.
1,489

edits