-
Notifications
You must be signed in to change notification settings - Fork 0
Execution
Matthew Joyce edited this page Feb 5, 2015
·
13 revisions
This cycle is repeated until a HLT instruction is encountered:
- Fetch the value from memory at the address of the instruction counter.
- Increment the instruction counter.
- Decode the instruction.
- Execute the instruction (e.g. add, or store).
- Store the result of the instruction in the accumulator.
E.G. If you had the memory:
901 902 000
The program would do:
- First cycle:
- The instruction counter is 0, so get the instruction at address 0 (
901). - Increment the instruction counter (so the instruction counter is 1).
- Decode the instruction (
INP). - Execute the instruction (get input from user).
- Store the result (what the user entered) in the accumulator.
- The instruction counter is 0, so get the instruction at address 0 (
- Second cycle:
- The instruction counter is 1, so get the instruction at address 1 (
902). - Increment the instruction counter (so the instruction counter is 2).
- Decode the instruction (
OUT). - Execute the instruction (print the accumulator value).
- Store the result (There was no result, so the accumulator is unchanged).
- The instruction counter is 1, so get the instruction at address 1 (
- Third cycle:
- The instruction counter is 2, so get the instruction at address 2 (
000). - Increment the instruction counter (so the instruction counter is 3).
- Decode the instruction (
HLT). - Execute the instruction (stop executing).
- The instruction counter is 2, so get the instruction at address 2 (
Note that errors during execution will halt the program.
-
Invalid instruction- The instruction is not recognised (the instruction is between 1 and 100 or between 903 and 1000). This is often because there is no halt instruction, so the data is being executed.
- Data is stored in a decimalised twos-complement (
999==-1,998==-2, ...,500==-500,499==499, ...,0==0), so when you putDAT -2in your program, it will generate the instruction998.