-------------------------
CHAPTER FOUR
THE 68000 INSTRUCTIONS
-------------------------
*** THE 68000 INSTRUCTIONS ***
---------------------------------
- Here is a chapter that is entirely dedicated to the different
68000 assembler instructions.
- Now that you know how to access data in memory thanks to addressing
modes, we will look at the instructions that allow to modify, move...
in other words to manipulate the data.
- For each instruction, I will give you:
.The syntax for the instruction and its operands.
.Its effects, its purpose.
.The addressing modes allowed for the operands.
.The effect of the instruction on the registers and notably on
the CCR.
.And of course some examples of use...
- New concepts will appear in the explanations concerning
instructions, they will be detailed, explained and commented.
--------------------
*** THE 68000 INSTRUCTIONS ***
---------------------------------
MOVE source,destination :(.B),[.W],(.L)
All three operation sizes are allowed for this instruction,
with [.W] being the default size.
The 'source' operand is copied (and remains unchanged) to (in)
the 'destination' operand.
The allowed addressing modes for the source operand are:
dn (data registers)
an (address registers)
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The allowed addressing modes for the destination operand are:
dn
an
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
Only the N and Z Bits of the CCR are affected.
Example of use:
Move.l #1456701,d0
The L-M equal to 1256701 is placed in the data register d0.
MOVEQ #D,dn
The source operand is an immediate, signed data contained in an
octet (-128<= D <128).
The destination operand is a data register.
The source data, signed and contained in an octet, is copied into a
data register with SIGN EXTENSION of the register:
Meaning that the data is placed in the least significant byte of
the Dn register and the MSB is extended (copied) up to the 31st bit of
the register, so that the data register is fully affected by the
'data loading' and the sign of the data is preserved.
The source operand therefore allows the addressing mode:
#BBB ( -128<= BBB <128 )
The destination operand is a data register.
Only the N and Z Bits of the CCR are affected by this instruction.
---
Example:
MOVEQ #%01100101,d0
The octet 01100101 is placed in d0:
d0= : 00000000000000000000000001100101
Bit nr 31 .
. .
MSB (0) <---------------MSB (0)
There has been sign extension of d0 (here MSB=0 because 01100101>0)
NB: Moveq is distinguished from Move by greater speed, but
-- remember the conditions of use of Moveq!
MOVEA source,an :(.W),(.L)
The Movea instruction complements the Move instruction as it accepts an
Address Register for the destination operand.
On most assemblers, the syntax MOVE source,an is
accepted and automatically translated to MOVEA source,an.
If the source operand uses the .W operation size, there is
sign extension of the address register an.
The .B size is not allowed for MOVEA.
The allowed addressing modes for the source operand are:
dn
an
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The destination operand is an address register
The MOVEA instruction does not affect the CCR.
---
Example of use:
MOVEA.L #etiq,a5
The address register a5 is loaded with the address pointed to by the
label 'etiq'.
LEA source,an : [.L]
This instruction reads: 'Load Effective Address'
Only the .L operation size is possible, and is the default.
It allows for placing the address pointed to by the source operand into
an address register.
The source operand allows the addressing modes:
BBBB
BB
(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The destination operand is an address register
------------------
The LEA instruction does not influence the CCR.
---
Example of use:
LEA etiq,a2
The address pointed to by the label 'etiq' is placed in the
address register a2.
In fact, this can also be done with MOVE.L #etiq,a2, but
it is less fast.
CLR destination :(.B),[.W],(.L)
This instruction reads: 'CLeaR destination'
And allows for setting all bits of the destination operand to 0.
All three operation sizes are possible.
The allowed addressing modes for the destination operand are:
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
The Z bit of the CCR is set to 1, the N, V, C bits to 0.
---
Example of use:
CLR.W D0
The 16 bits of the least significant word of d0 are set to 0.
NEG destination : (.B),[.W],(.L)
Allows for performing the NEGation of the destination operand.
All three operation sizes are possible.
The destination operand is subtracted from 0, which has the effect of
changing the sign of the operand: Bits that were active are
turned off and bits that were off are activated.
The destination operand allows the following addressing modes:
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
All Bits of the CCR are affected by the NEGation depending on the
result obtained.
---
Example of use:
MOVE #%1010101010101010,d0
NEG.W d0
The word %0101010101010101 is obtained in d0.
EXT dn : [.W],(.L)
Allows for sign EXTension of the destination operand.
The .B size is not allowed.
In the case of EXT.W dn:
The MSB (bit no. 7) of the data register is extended up to bit no. 15
In the case of EXT.L dn:
The MSB (bit no. 15) of the data register is extended up to bit no. 31
This allows for extending the content of the data register into a WORD
or into an L-M while preserving the sign of the register.
The destination operand can only be a data register.
The N and Z Bits of the CCR are set according to the result of
the operation. ---
Example of use:
MOVE.W #%0001011001010010,d5
EXT.L d5
The MSB (here 0) will be copied from bit no. 16 to bit no. 31, so d5 will contain
an L-M: %00000000000000000001011001010010, not just a WORD.
EXG rn,rm
EXG allows for swapping the contents of two dn or an registers.
The .L size is the default
The source operand is a data or address register
The destination operand is a data or address register
The CCR is not affected by EXG
---
Example of use:
MOVE.L #$FF,d0
MOVE.L #$A2,d1
EXG d1,d0
D0 will contain the L-M $A2 and d1 the L-M $FF.
SWAP dn
Swaps the two WORDS of the L-M contained in the data register dn
The destination operand must be a data register.
The N and Z Bits of the CCR are affected according to the result obtained.
---
Example of use:
MOVE.L #%11111111111111110000000000000000,d3
SWAP d3
D3 will contain the L-M: %00000000000000001111111111111111
Note that the sign of the dn register is not preserved and can be changed!
ADD dn,destination :(.B),[.W],(.L)
or
ADD source,dn :(.B),[.W],(.L)
Adds the source operand INTO the destination operand (the source
operand is therefore unchanged and the result is found in the destination
operand! )
All three operation sizes are accepted.
The allowed addressing modes for the source operand when ADD
is written: ADD.x source,dn are: ------
----------------
dn
an
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
If the source operand is an address register, the .B size is
not allowed; if the size is .W, there is sign EXTension of an.
The allowed addressing modes for the destination operand when ADD
is written ADD.x dn,destination are: -----------
---------------------
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
All Bits of the CCR may react to the ADD operation depending on
the result obtained.
Example of use:
ADD.B d0,d1
The least significant byte of the data register d0 is added to
the least significant byte of d1, the result is in d1:
d0=d0, d1=d1+d0
ADDI #BBB,destination :(.B),[.W],(.L)
ADDI reads: 'ADD Immediate'
All three operation sizes are allowed.
The immediate data source is added to the destination operand.
The addressing modes allowed for the destination operand are:
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
All 5 codes of the CCR are affected by ADDI
---
Example of use:
ADDI.W #12,(a0)
The word 12 is added to the word pointed to by the address register a0.
ADDQ #BBB,destination :(.B),[.L],(.L)
The unsigned immediate data #BBB is added INTO the destination
operand.
It is mandatory that 1<= #BBB <=8
The destination operand allows the addressing modes:
dn
an
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
If the destination operand is an address register an, the .B size
is forbidden; if the .W size is used, there will be sign EXTension
of an to an L-M.
All 5 Bits of the CCR are modified by ADDQ depending on the result.
---
Example of use:
ADDQ.W #3,d0
Adds the word 3 to the least significant word of d0.
Note: ADDQ is faster than ADDI, which explains the name
of the instruction: ADD Quick
Be aware that 1<= #BBB <=8
ADDA source,an :(.W),(.L)
This instruction reads: 'ADD Address'
It complements ADD as here the destination operand is an address
register. ----------- --------
Only .W and .L sizes are allowed.
ADDA adds the source operand to the address register an.
The allowed addressing modes for the source operand are:
dn
an
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The CCR is not modified by ADDA
---
Example of use:
ADDA.L #2,a0
a0 is incremented by 2 units.
SUB dn,destination :(.B),[.W],(.L)
or
SUB source,dn :(.B),[.W],(.L)
Subtracts the source operand FROM the destination operand (the source
operand is therefore unchanged and the result is found in the destination
operand! )
All three operation sizes are accepted.
The allowed addressing modes for the source operand if SUB
is written: SUB.x source,dn are: ------
----------------
dn
an
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
If the source operand is an address register, the .B size is
not allowed; if the size is .W, there is sign EXTension of an.
The allowed addressing modes for the destination operand if SUB
is written SUB.x dn,destination are: -----------
---------------------
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
All Bits of the CCR may react to the SUB operation depending on
the result obtained.
Example of use:
SUB.B d0,d1
The least significant byte of the data register d0 is subtracted from
the least significant byte of d1, the result is in d1:
d0=d0, d1=d1-d0
SUBI #BBB,destination :(.B),[.W],(.L)
SUBI reads: 'SUBtract Immediate'
All three operation sizes are allowed.
The immediate data source is subtracted from the destination operand.
The addressing modes allowed for the destination operand are:
dn
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
All 5 codes of the CCR are affected by SUBI
---
Example of use:
SUBI.W #12,(a0)
The word 12 is subtracted from the word pointed to by the address register a0.
SUBQ #BBB,destination :(.B),[.L],(.L)
The unsigned immediate data #BBB is subtracted FROM the destination
operand.
It is mandatory that 1<= #BBB <=8
The destination operand allows the addressing modes:
dn
an
BBBB
BB
(an)
(an)+
-(an)
d(an)
d(an,rn)
If the destination operand is an address register an, the .B size
is forbidden; if the .W size is used, there will be sign EXTension
of an to an L-M.
All 5 Bits of the CCR are modified by SUBQ depending on the result.
---
Example of use:
SUBQ.W #3,d0
Subtracts the word 3 from the least significant word of d0.
Note: SUBQ is faster than SUBI, which explains the name
of the instruction: SUBtract Quick
Be aware that 1<= #BBB <=8
SUBA source,an :(.W),(.L)
This instruction reads: 'SUBtract Address'
It complements SUB as here the destination operand is an address
register. ----------- --------
Only .W and .L sizes are allowed.
SUBA subtracts the source operand from the address register an.
The allowed addressing modes for the source operand are:
dn
an
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The CCR is not modified by SUBA
---
Example of use:
SUBA.L #2,a0
a0 is decremented by 2 units (similar to .W, -(a0) ).
MULS source,dn
Allows a Signed MULtiplication of the source operand INTO the
data register dn.
The relative integer 'source' is extended to 16 bits and is multi-
plied by the least significant word of dn. -------
---
The result is in dn and it is an L-M, SIGNED relative integer.
--- ------
The source operand accepts the following addressing modes:
------
dn
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The V and C bits of the CCR are set to 0, the N and Z bits are positioned
according to the result, X is not affected.
Example of use:
MOVE.W #3,D0
MULS #-5,D0
D0 will contain the L-M equal to 3*(-5)=-15
MULU source,dn
Allows an Unsigned MULtiplication (Unsigned) of the source operand
INTO the data register dn.
The relative integer 'source' is extended to 16 bits and is multi-
plied by the least significant word of dn. -------
---
The result is in dn and it is an L-M, UNSIGNED relative integer.
--- ----------
The source operand accepts the following addressing modes:
------
dn
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The V and C bits of the CCR are set to 0, the N and Z bits are positioned
according to the result, X is not affected.
Example of use:
MOVE.W #4,d2
MULU #3,d2
D2 will contain the L-M equal to 4*3=12
DIVS source,dn
Allows a Signed Division of the data register dn by the
relative integer extended to 1 word 'source'.
The relative integer 'source' is extended to 16 bits and is the divisor
of the data register dn. -------
The result is in dn and it is an L-M, SIGNED relative integer such that:
--- -----
The quotient occupies the least significant word of dn.
--------
The remainder (if any) has the sign of the dividend and occupies the
-----
most significant word of dn.
The source operand accepts the following addressing modes:
------
dn
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The C bit of the CCR is set to 0, the N, Z, V bits are positioned according
to the result, the X bit is not affected.
Example of use:
MOVE.W #4,D2
MOVE.W #12,D0
DIVS D2,D0
MOVE.L D0,RES
BSS
RES DS.W 1
QUO DS.W 1
The word pointed to by QUO contains 3 and the word pointed to by RES contains
0 because there is no remainder.
Note: To easily reach the two words (remainder/quotient) of the destination
data register, one can, for example, use the previously seen 'SWAP dn'
instruction.
.If one performs a division by 0, this leads to an exception
procedure and interrupts the execution of the program!
(I will explain later what exception procedures are.)
DIVU source,dn
Allows an UNSIGNED Division of the data register dn by the
relative integer extended to 1 word 'source'.
The relative integer 'source' is extended to 16 bits and is the divisor
of the data register dn. -------
The result is in dn and it is an L-M, UNSIGNED relative integer
such that: --- ---------
The quotient occupies the least significant word of dn.
--------
The remainder (if any) occupies the most significant word of dn.
-----
The source operand accepts the following addressing modes:
------
dn
BBBB
BB
#BBB
(an)
(an)+
-(an)
d(an)
d(an,rn)
d(pc)
d(pc,rn)
The C bit of the CCR is set to 0, the N, Z, V bits are positioned according
to the result, the X bit is not affected.
Note: It is important to ensure that the data ('source' and 'dn') are
positive and that the source operand is different from 0!
.Instructions that operate on unsigned data are
faster than their complementary instructions that operate
on signed data (MULS/MULU, DIVS/DIVU), this is their
only advantage.
The MULS and DIVS instructions can of course also operate
on positive instructions.