Title: 68332 Basic Instructions
168332 Basic Instructions
- Structure of an instruction
2Basic Instructions
- Each instruction has an associated instruction
template. - This defines the word data required to encode the
instruction (i.e.just fill in the bits).
3- Source Where to find data
- Destination Where to copy data
- Size field
- 01 -gt byte operation
- 11 -gt word operation
- 10 -gt long operation
- Register Which register to use (if none then
used for other purposes. ) - Mode Defines the data format/location
4Copying from Data Register to Data Register
Destination Mode 000 Source Mode
000 Example move a word of data from d5 to
d3
The instruction is fully self contained -gt no
extra operand data is necessary!
5Example Program
- Copy value in register d3 to register d0, d1 and
d2 - What instruction sequence is required?
- Move word d3 -gt d0
- Move word d3 -gt d1
- Move word d3 -gt d2
- Where do we locate the code in memory? -gt 4000
4000 30 03 D0 lt- D3 4002 32 03 D1 lt-
D3 4004 34 03 D2 lt- D3
6Copying from Memory to Data Register
-gt Source Memory -gt Source Mode
111 Source register field encodes memory
address length 000 if memory address is
16-bit 001 if memory address is 32-bit Assume
all addresses are 32-bit (long-words). 16-bit
address used for compact programs and limit the
available address space.
7Example
Copy (word) contents of memory at 2000 into
register D3
This instruction requires an operand memory
address
4000 36 39 Move 2000 -gtD3 4002 00 00
4004 20 00
8Why is the operand 2 words in length?
- We are not moving the value 2000 into d3
register, rather the contents of memory location
2000 - Note
- We may not know the contents at this point.
- This is known as absolute addressing
9Example Program
4000 3639 Move 2000 -gt D3 4002 0000 4004 20
00 4006 3003 D0 lt- D3 4008 3203 D1 lt-
D3 400A 3403 D2 lt- D3
This program copies the word at 2000 into D3 and
then copies from there into D0, D1, and D2
10How is the PC updated?
- Recall the FETCH-gtDECODE-gtEXECUTE cycle
- CPU determines the number of operands by looking
at the mode fields of the instruction during
decoding - -gt It adds 4 to the PC to skip over the 4 byte
operand - Remember the PC is immediately incremented by 2
as soon as the instruction is read in
11The Complete Sequence of events
1. Fetch instruction at 4000 2. PC lt- PC
2 3. Decode instruction 4. PC lt- PC
4 5. Execute Move word from 2000 -gt D3 6. Fetch
instruction at 4006 7. PC lt- PC 2 8. Decode
instruction 9. Execute Move data from D3 -gt
D0 10. Fetch instruction at 4008 11. PC lt- PC
2 12. Decode instruction 13. Execute Move
data from D3 -gt D1 14. Fetch instruction at
400A 15. PC lt- PC 2 16. Decode
instruction 17. Execute Move data from D3 -gt D2
12Copying from Memory to Memory
-gt Source Destination Memory -gt Source
Destination Mode Register 111 000 If
memory address is 16-bit 111 001 If memory
address is 32-bit Example Move a word from
2002 to 200A 0 0 11 001 111
111 001 -gt 33F9
13Memory to Memory Program
4000 33F9 move.w 2002 -gt 200A 4002 0000
Source operand 4004 2002 4006 0000
Destination operand 4008 200A
- This instruction requires 2 operands, each 2
words long. - The source always precedes the destination if
multiple operands are required. - The PC will have to be incremented by 8 Bytes (as
well as the normal 2 bytes) to point to the next
instruction.
14Immediate Value to Data Register
- In previous examples we have referred to either a
memory location or a data register. - -gt A location where the data is stored.
- Sometimes we need to specify a given value known
as an immediate value. - -gt Use immediate addressing mode.
15Example Move Value 10 into D2
-gt Source mode immediate mode
111 -gt Source register immediate mode
100 0 0 11 010 000 111
100 -gt 343C
16Immediate Values Symbol
- We distinguish immediate values from addresses
using sysmbol - 1000 Decimal value 1000
- 1000 Hexadecimal value 1000
- 1000 Address 1000 (decimal)
- 1000 Address 1000 (hexadecimal)
17Mnemonics
Template for a move instruction.
- Difficult to remember templates for each
instruction. - Well replace this with the sysmbol (mnemonic)
- move
- Replace the size feld with the b, w and l
subscripts - move.b -gt move a byte
- move.w -gt move a word
- move.l -gt move a long word
18Encode Operands and the Destination/Source Modes
- The operands and the destination /source modes
are encoded as arguments following the
symbol(src, dest) - move.b d0,d1
- move.w 2000,d5
- move.l 2000, 200A
- move.l 10, d2
- Assembler sysntax for the move command is
- move lteagt lteagt
- lteagt effective address an expression which,
when evaluated, produces a value.
19Move
20Defaults
- In order to simplify coding of assembly language,
certain defaults are assumed - move -gt move.w (i.e. word size is default)
- move 10,d2 -gt absolute addressing
- 10 -gt decimal 10
21Addressing Restrictions
Only Bytes may be read from ODD memory
addresses. Words and Long-words must be read
from EVEN memory addresses!
- This was a design decision to simplify memory
interfacing. - Accessing words or long-words on odd boundaries
causes the 68000 to terminate the F-gtD-gtE cycle. - -gt An address error occurs
22Which of these instruction is legal?
a) move.w 4001, d0 b) move.b 4004, d1 c) move.b
4003, d3 d) move.w 4001, 4003 e) move.b 4000,
4001