Tutorial2 ProgrammingModel2
Tutorial2 ProgrammingModel2
Introduction
Objectives
At the end of this lab you should be able to:
Basic Theory
The programming model of computer architecture defines those
low-level architectural components, which include the following
Registers
Simulator Details
This section includes some basic information on the simulator, which
should enable the students to use the simulator. The tutor(s) will be
available to help anyone experiencing difficulty in using the simulator.
The simulator for this lab is an application running on a PC and is
composed of a single window.
Instruction memory
Special registers
Register set
Hardware stack
The parts of the simulator relevant to this lab are described below.
Image 3 - Special
registers view
Image 6 - Program
Instructions View
IMPORTANT NOTE:
Before you carry on with the following tutorial exercises, first click on
the SHOW PIPELINE button in the CPU Simulator window and
check the checkbox labelled No instruction pipeline. Close the
window.
You are now ready to enter instructions into this view. You do this by
clicking on the ADD NEW button. This will display the Instructions:
CPU0 window. Use this window to enter the instructions. For your
reference Appendix provides a list of instructions for the CPU
simulator.
Now, do the following activities:
6
e.g.
MOV #2, R01 ;moves number 2 into register R01
MOV R01, R03 ;moves contents of register R01 into register R03
Load a byte from memory to register
LDB
e.g.
LDB 1000, R02 ;loads one byte value from memory location 1000
LDB @R00, R01 ;memory location is specified in register R00
Load a word (2 bytes) from memory to register
LDW
e.g.
LDW 1000, R02 ;loads two-byte value from memory location 1000
LDW @R00, R01 ;memory location is specified in register R00
Store a byte from register to memory
STB
e.g.
STB #2, 1000 ;stores value 2 into memory location 1000
STB R02, @R01 ;memory location is specified in register R01
Store a word (2 bytes) from register to memory
STW
e.g.
STW R04, 1000 ;stores register R04 into memory location 1000
STW R02, @2000 ;memory location is specified in memory 2000
Push data to top of hardware stack (TOS); push register to TOS
PSH
e.g.
PSH #6 ;pushes number 6 on top of the stack
PSH R03 ;pushes the contents of register R03 on top of the stack
Pop data from top of hardware stack to register
POP
e.g.
POP R05 ;pops contents of top of stack into register R05
Arithmetic instructions
Add number to register; add register to register
e.g.
ADD
SUB
MUL
DIV
e.g.
JMP 100 ;unconditionally jumps to address location 100
Jump to instruction address if less than (after last comparison)
JLT
JGT
e.g.
JLT 1000 ;jumps to address location 1000 if the previous
comparison instruction result indicates that CMP operand 2 is less
than operand 1.
Jump to instruction address if greater than (after last comparison)
Jump to instruction address if equal (after last comparison)
JEQ
e.g.
JEQ 200 ;jumps to address location 200 if the previous comparison
instruction result indicates that the two CMP operands are equal.
JNE
CAL
RET ;will jump to the instruction after the last CAL instruction.
SWI
HLT
e.g.
HLT ;stops the simulation run (not the simulator itself)
Comparison instruction
Compare number with register; compare register with register
e.g.
CMP #5, R02 compare number 5 with the contents of register R02
CMP
CMP R01, R03 compare the contents of registers R01 and R03
Note:
If R03 = R01 then the status flag Z will be set
If R03 > R01 then non of the status flags will be set
If R03 < R01 then the status flag N will be set
OUT
10