FIRST Robotic Competition - Program Execution
Lets store that program at location 100 and execute it.
Note that the opcodes I show would actually be numbers.
For simplicity I will show them as nmemonics instead.
Our program in main memory looks like this:
MVI 1,R0 ; prod = 1
MVI 2,R2 ; index=2
Loop1:
ADD R0,R2 ; prod + index
MOV ACC,R0 ; prod =
DCR R2 ; index-1
MOV ACC,R2 ; index =
JNZ Loop1 ; for()
|
Address
|
Data
|
|
100
|
MVI R0
|
|
101
|
1
|
|
102
|
MVI R2
|
|
103
|
2
|
|
104 [Loop1]
|
ADD R0,R2
|
|
105
|
MOV ACC,R0
|
|
106
|
DCR R2
|
|
107
|
MOV ACC,R2
|
|
108
|
JNZ
|
|
109
|
104 [Loop1]
|
To execute this code we start with the PC set to 100.
- Start
- PC=100
The PC is copied to the MA.
- MA=PC=100
The RAM location 100 is copied to the MDI.
- MDI=MVI R0; PC=PC+1=101
The MDI is copied to the IR.
- 100: MVI 1,R0
- IR=MVI R0
The instruction is decoded.
The PC is copied to the MA.
- MA=PC=101
The RAM location 101 is copied to the MDI.
- MDI=1
The MDI is copied to R0.
- R0=MDI=1; PC=PC+1=102
- MA=PC=102
The RAM location 102 is copied to the MDI.
- MDI=MVI R0; PC=PC+1=103
The MDI is copied to the IR.
- 102: MVI 2,R2
- IR=MVI R2
The instruction is decoded.
The PC is copied to the MA.
- MA=PC=103
The RAM location 102 is copied to the MDI.
- MDI=2
The MDI is copied to R0.
- R2=MDI=2; PC=PC+1=104
- MA=PC=104
The RAM location 104 is copied to the MDI.
- MDI=ADD R0,R2; PC=PC+1=105
The MDI is copied to the IR.
- 104: ADD R0,R2
- IR=ADD R0,R2
- ACC=R0+R2=3
- MA=PC=105
The RAM location 105 is copied to the MDI.
- MDI=MOV ACC,R0; PC=PC+1=106
The MDI is copied to the IR.
- 105: MOV ACC,R0
- IR=MOV ACC,R0
- R0=ACC=3
- MA=PC=106
The RAM location 100 is copied to the MDI.
- MDI=DCR R2; PC=PC+1=107
The MDI is copied to the IR.
- 106: DCR R2
- IR=DCR R2
- ACC=R2-1=1
- MA=PC=107
The RAM location 107 is copied to the MDI.
- MDI=MOV ACC,R2; PC=PC+1=108
The MDI is copied to the IR.
- 107: MOV ACC,R2
- IR=MOV ACC,R2
The instruction is decoded.
- R2=ACC=1
- MA=PC=108
The RAM location 108 is copied to the MDI.
- MDI=JNZ; PC=PC+1=109
The MDI is copied to the IR.
- 108: JNZ Loop1
- IR=JNZ
The instruction is decoded.
- MA=PC=109
Since ACC is not zero, we jump to Loop1.
- MDI=Loop1=104
- PC=MDI=104
- MA=104
- MDI=ADD R0,R2; PC=PC+1=105
- 104: ADD R0,R2
- IR=ADD R0,R2
- ACC=R0+R2=4
- MA=PC=105
The RAM location 105 is copied to the MDI.
- MDI=MOV ACC,R0; PC=PC+1=106
The MDI is copied to the IR.
- 105: MOV ACC,R0
- IR=MOV ACC,R0
- R0=ACC=4
- MA=PC=106
The RAM location 100 is copied to the MDI.
- MDI=DCR R2; PC=PC+1=107
The MDI is copied to the IR.
- 106: DCR R2
- IR=DCR R2
- ACC=R2-1=0
- MA=PC=107
The RAM location 107 is copied to the MDI.
- MDI=MOV ACC,R2; PC=PC+1=108
The MDI is copied to the IR.
- 107: MOV ACC,R2
- IR=MOV ACC,R2
The instruction is decoded.
- R2=ACC=0
- MA=PC=108
The RAM location 108 is copied to the MDI.
- MDI=JNZ; PC=PC+1=109
The MDI is copied to the IR.
- 108: JNZ Loop1
- IR=JNZ
The instruction is decoded.
- MA=PC=109
Since ACC is zero, we don't jump.
- PC=PC+1=10A
- MA=10A
- MDI=next instruction; PC=PC+1=10B
The result of this loop, prod, is stored in R0.
It was computed the second time thru location 105.
That value is 4.
Last modified 11 Dec 2006
http://brown.armoredpenguin.com/~abrown/contact.html
http://brown.armoredpenguin.com/~abrown/first/training/ComputerBasics/execution.html