next up previous contents index

[ENGN3213 Home]

Examples

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.


  
Figure 107: 68000 instruction assembly for MOVE.W #$2468,D0 .
\begin{figure}
\begin{center}
\epsfig{file=images/68k-move-1.eps}\end{center}\end{figure}

The instruction

MOVE.W D0,$1FF0
moves (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:

This gives 0011 0001 1100 0000 = 31C0, hence:

00002004 31C0 1FF0
00002008
Here 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.

In HLAB6 we consider the 5206 instruction

MOVE.W %D0,0x20000
written in GCC syntax (C style). Because the destination operand is a 32-bit value, the assembler uses absolute long:

00010004 33C0 0002
00002008 0000
0001000A
Here the destination operand occupies 4 bytes of memory.

Hand coding uses the 5206 Programmer's Reference Manual, page 4-53:

This gives 0011 0011 1100 0000 = 33C0.

In CLAB5 you hand coded the ADDQ instruction

ADDQ.W #1,D0
You should have got:

00002004 5240
00002006
The data is part of the main opcode, and no subsequent operand bytes are used.

Figure 108 shows the ADDQ instruction code format for this example.


  
Figure 108: 68000 instruction assembly for ADDQ.W #1,D0.
\begin{figure}
\begin{center}
\epsfig{file=images/68k-addq-1.eps}\end{center}\end{figure}

This gives = 0101 0010 0100 0000 = 5240.


next up previous contents index

[ENGN3213 Home]

ANU Engineering - ENGN3213