3 Instructions Set
3 Instructions Set
A0 $1000
$1232
A1 $2000
$1235
A2
CpE 351 – Fall 08 4
MOVE TO CCR
Set to CCR a specific value
MOVE <ea>,CCR – word instruction
MOVE.W #0,CCR: Reset all flags of CCR
MOVE.W #1,CCR: Set Carry flag at 1
MOVE.W #%10,CCR: Set overflow at 1
MOVE.W #%10001,CCR: Set X and C at 1
No move from CCR? How to read CCR?
X N Z V C
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
T S I2 I1 I0 X N Z V C
Example
A1= $1000
D1=$12345678
movep D1,0(A1)
$12 to loc $1000
$34 to loc $1002
$56 to loc $1004
$78 to loc $1006
MOVE #35, D1 ;
LSL.W D1, D3 ;Logically shift right D3 contents 3 bits
(35-32)
MOVE.L #10, D1 ;
LSR.W D1, D6 ;Logically shift right D6 contents 10 bit
LSR.W (A1) ;Logically shift memory (A1) by 1
Effective address of
the operand
The displacement is the different between the current PC (i.e.
PC+2) and the <label>
8-bit displacement can be forced by adding .S extension
If the branch condition is set, a branch to <label> is made. If
not, the instruction immediately following the branch is
executed.
Example
BEQ Loop ;Loop stands for disp., not its address
BCC *+8 ;If C=0 branch 8 bytes ahead of PC
ZNCV bits are used to decide
CpE 351 – Fall 08 53
Branch Conditions
Cond. Meaning Branch taken if:
CC Carry Clear C=0
CS Carry Set C=1
NE Not Equal Z=0
EQ Equal Z=1
PL Plus N=0
MI Minus N=1
HI Higher than C’ . Z’ = 1
LS Lower or Same C + Z = 1
GT Greater than N . V . Z’ + N’ . V’ . Z’ = 1
LT Less Than N . V’ + N’ . V = 1
GE Greater or Equal N . V’ + N’ . V = 0
LE Less or Equal Z + (N’ . V + N . V’) = 1
VC Overflow Clear V = 0
VS Overflow Set V=1
T Always True Always
F Always False Never
NOP
No effect on the CPU other than advancing the PC to the
next instruction
Waste time and memory space
Sometimes used to generate delays.
Sometimes it is replaced with future code.
Stop
STOP #<data>
IF [S] = 1 THEN [SR] = <data> ELSE TRAP
Loads <data> into SR, advance PC then freeze
Resumes execution when an interrupt or a reset
exception occurs
Privileged instruction
A trace exception begins when STOP starts
executing if the T bit is enabled
Interrupts higher than current level get
serviced, others ignored
Used for Debugging
Trap and Trap on Overflow
TRAP #<vector>
[SSP] = [SSP] - 4; [M([SSP])] = [PC];
[SSP] = [SSP] - 2; [M([SSP])] = [SR];
[S] = 1;
[PC] = address (vector);
Generate an exception, first it switches to supervisor
mode, save PC on stack, then gets the address of the
exception show specified by vector (0, 1 , 2, … , 15)
Debugging, Print/Display Services like your simulator
Interrupts higher than current level get serviced, others
ignored
S bit is restored upon executing RTE at the end of
exception
SSP is used, even if S is not 1 upon starting TRAP
TRAPV is a dedicated one, no vector, and gets executed
only if V=1
Check Register Against Bounds
CHK <ea>, Dn
Check the low order word of Dn against two
bounds
If Dn(0:15) < 0 OR Dn(0:15) > <ea> then a call to OS
is made
Else, next instruction in sequence is executed
Used by compilers to test whether an array is
being accessed outside its declared bounds
Subroutines
Subroutine is a coherent sequence of instructions that can
be called from some point in a program to carry out a well
defined function, preferably single one
This allows using the sequence many times without writing
it as many
It makes the program modular, hence more readable and
maintainable
Usually have entry point and exit point
One may or may not need input data, and may or may not
return data
Subroutines can be nested, one calling another
Subroutine can be recursive, one calling itself many times
Subroutine with destructive register access, must save
registers and CCR upon entering and restore upon exiting,
along with CCR
Subroutines
BRANCH TO SUBROUTINE
BSR <label> = [A7] [A7] - 4
M([A7])] [PC]
[PC] [PC] + d8
current PC value