Reputation: 31
I have to define the steps for each Little Man Computer instruction (ADD, SUB, BR, BRP etc.), and I'm having trouble with the branching instructions and COB (or the Halt instruction). I understand the fetch portion where each instruction begins with:
PC -> MAR
MDR -> IR
But I'm unsure of what to add in the execute portion to make the instruction actually correct. Could anyone explain how to make the fetch-execute cycles for BR, BRP, BRZ and COB? Any help would be greatly appreciated
Upvotes: 2
Views: 777
Reputation: 350335
First of all, the LMC is a virtual concept. It has several interpretations and implementations, which can sometimes be conflicting. So which answer is correct may depend on the course material you are working with.
To avoid confusion, here are the definitions we could use:
The fetch part of the fetch-execution cycle is always the same -- I prefer to write assignments in the opposite direction:
We could debate the exact order of the last step. The update of the PC could happen before or in parallel with steps 2 and 3.
The execution part of the fetch-execution cycle depends on the content of IR: the opcode (1 digit, or 901 or 902 for IN
/OUT
) is interpreted. For instance:
BR
(also named BRA
):
PC <= IR(last 2 digits)
BRP
:
If N is not set:
PC <= IR(last 2 digits)
BRZ
:
If Z flag is set:
PC <= IR(last 2 digits)
COB
:
Program execution halts. No more fetch-execution cycle will follow until the external user triggers a run.
Depending on your course material, you may not be expected to mention the N or Z flags. In that case just replace the conditionals with "ACC is negative" and "ACC is zero" respectively.
Note that I didn't involve the MAR or MDR registers for these four instructions -- moving values from IR to PC directly -- as MAR and MDR are only needed for communication between the processing unit and memory.
Upvotes: 1