Let's look at some examples from the labs.
MOVE.W #$2468,D0
This instruction (from CLAB5) moves the immediate data value (word) #$2468 into D0[15:0].
When this instruction is assembled into machine code at addresss $2000 we get:
00002000 303C 2468
00002004
The complete instruction uses 4 bytes, or 32 bits, in memory locations $2000, $2001, $2002, $2003. The basic instruction code occupies the first 2 bytes, and the data the remaining 2 bytes.
In general, instructions are assembled into an instruction code plus operand (which may be data or address information). The number of bytes required depends on the instruction and the addressing mode.
We rarely need to assemble instructions by hand, but it useful to know how this is done and to practice with at least a few short examples.
Let's assemble the above instruction by hand. We need the information given in page 4-116 of the 68000 Programmer's Reference Manual for the MOVE instruction. Figure 107 shows the MOVE instruction code format for this example.
The instruction
MOVE.W D0,$1FF0moves (i.e. copies) the contents of D0[15:0] to memory location $1FF0, so that after execution ($1FF0) = 24, ($1FF1) = 68. We can hand code this as follows:
00002004 31C0 1FF0Here we have used the short form of absolute addressing, which specifies a 16-bit address operand (the assembler makes this choice). The destination operand uses 2 bytes of memory.
00002008
In HLAB6 we consider the 5206 instruction
MOVE.W %D0,0x20000written in GCC syntax (C style). Because the destination operand is a 32-bit value, the assembler uses absolute long:
00010004 33C0 0002Here the destination operand occupies 4 bytes of memory.
00002008 0000
0001000A
Hand coding uses the 5206 Programmer's Reference Manual, page 4-53:
In CLAB5 you hand coded the ADDQ instruction
ADDQ.W #1,D0You should have got:
00002004 5240The data is part of the main opcode, and no subsequent operand bytes are used.
00002006
Figure 108 shows the ADDQ instruction code format for this example.
ANU Engineering - ENGN3213