Skip to content
Matthew Joyce edited this page Jan 28, 2015 · 13 revisions

Execution

Execution Cycle

This cycle is repeated until a HLT instruction is encountered:

  1. Fetch the value from memory at the address of the instruction counter.
  2. Increment the instruction counter.
  3. Decode the instruction.
  4. Execute the instruction (e.g. add, or store).
  5. 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.
  • 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).
  • 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).

Execution Errors

Note that errors during execution will halt the program.

  • Invalid instruction - The instruction is not recognised.
  • Invalid memory address - The address is not in the range (0 - 99).

Other Facts

  • Data is stored in a decimalised twos-complement (999 == -1, 998 == -2, ..., 500 == -500, 499 == 499, ..., 0 == 0), so when you put DAT -2 in your program, it will generate the instruction 998.

Next page: The CLI or The GUI

Clone this wiki locally