Cpu Tutorial 2
Cpu Tutorial 2
RKtiwary
1. CPU instruction
memory view
1. CPU instruction
memory view
Image2 Instruction
memory view
Image 4 CPU
Image 4 CPU
4. Program stack
view
Image 5 Program
stack view
4. Program stack
view
Image 6Program
List View
6. Program
creation
Image 7Create
program tab
7. Program data
memory view
Image 9
Program data
memory view
The CPU instructions
that access that part
of the memory
containing data can
write or read the
data in addressed
locations. This data
can be seen in the
memory pages
window shown in
Image 9 above. You
can display this
window by clicking
8. IO console view
Arithmetic instructions
ADD Add number to register; add register to register
e.g.
ADD #3, R02 adds number 3 to contents of register R02 and
stores the result in register R02.
ADD R00, R01 adds contents of register R00 to contents of
register R01 and stores the result in register R01.
SUB Subtract number from register; subtract register from
register
MUL Multiply number with register; multiply register with register
DIV Divide number with register; divide register with register
Comparison instruction
CMP Compare number with register; compare register
with register
e.g.
CMP #5, R02 compare number 5 with the contents of
register R02
CMP R01, R03 compare the contents of registers R01
and R03
Note:
If R01 = R03 then the status flag Z will be set, i.e. the Z
box is checked.
If R03 > R01 then non of the status flags will be set, i.e.
none of the status flag boxes are checked.
Now, lets create a loop. First, enter the following code. The #
prefix is used to denote a literal value thus distinguishing it
from an address value which does not use it. R01 represents
an arbitrary register; you can use any of the registers from
R00 to R31
MOV #0, R01
ADD #1, R01
CMP #5, R01
JNE 0
HLT
in order to make the code more flexible we can use labels to
represent instruction addresses
lets get a little bit more ambitious as a challenge. Lets convert the loop
into another subroutine and then call it. So, now we will have two
subroutines where one calls the other. The following code represents this
change
MSF
CAL $L2
HLT
L2:
MOV #0, R01
L0:
ADD #1, R01
MSF
CAL $L1
CMP #5, R01
JNE $L0
RET
L1:
OUT 24,0
MSF
PSH #8
CAL $L2
HLT
L2:
POP R02
L0:
ADD #1, R01
MSF
CAL $L1
CMP #5, R01
JNE $L0
L1:
OUT 24,0
RET
Data
Hits
block