So how does a program actually run?

The user's original program must first be translated into machine code. The instructions that make up this machine code can be called macro-instructions (as opposed to the micro-instructions). These macro-instructions are the basic instructions that make up a user's program. When the instruction set (the set of all micro-instructions stored in the control store is executed, it interprets each macro-instruction and executes the command. Macro-instructions are composed of opcodes and addresses. Opcodes are the part of the macro-instruction that tells the computer what the instruction actually is, while the address tells the computer where the data that the instruction acts on is. Each computer has its own unique set of macro-instructions, with varying numbers of opcodes, and varying numbers of addresses for each opcode. In our example, in order to keep things simple, we have implemented a one-address machine. This means that every opcode has only one address with it. The results of every operation are stored in the AC register for use by future instructions. Our macro-instruction set is made up of sixteen instructions, each four bits long with a twelve bit address:

Here is an example of how our microarchitecture would execute a user's program stored in main memory. It is just one Add Indirect instruction, Add Indirect 5 to be exact. After each microinstruction will be a short explanation and a list of the contents of the registers.
    Address     Contents
    0           1010000000000101
    3           0000000000010001  (the number 17)
    5           0000000000000011  (the number 3)
   
Micro-instruction 0: mar=pc;rd; The contents of the PC are copied into the MAR and data starts to load from the memory address denoted by the MAR.
    PC:                 0
    AC:                 0
    IR:                 0
    TIR:                0
    MAR:                0
    MBR: 1111111111111111
   
Micro-instruction 1: pc=pc+1;rd; The contents of the PC is incremented and the read cycle is completed.
    PC:                 1
    AC:                 0
    IR:                 0
    TIR:                0
    MAR:                0
    MBR: 1010000000000101
   
Note that the first four bits from the left are the opcode for Add Indirect, while the remaining bits form the number '5' in binary.

Micro-instruction 2: ir=mbr;if n goto 22; The macro-instruction that is in the MBR is loaded into the IR. If the N output of the ALU is 1, (negative result) the next micro-instruction to be executed would be #22. Using the N flag from the ALU allows the program to test one bit of the instruction at a time, throwing away half the possibilities of what instruction it is at each test. This way the computer can determine which instruction to execute in (in our example) at the most four tests.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR:                0
    MAR:                0
    MBR: 1010000000000101
   
Note that N is 1 in this case.

Micro-instruction 22: tir=lshift(ir);if n goto 26; A copy of the contents of the IR are left shifted and stored into the TIR. Another goto check is performed. Left shifting the IR will move the next bit of the instruction into the last place so the ALU's N flag can check it, but this also moves the address field (which is bad). So the instruction must be stored in a temporary register (TIR) while the original remains intact in IR.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 0100000000001010
    MAR:                0
    MBR: 1010000000000101
   
Micro-instruction 23: mar=ir&amask;rd; MAR is set to IR AND'ed with AMASK (thus isolating the address) and a read cycle is begun.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 0100000000001010
    MAR:     000000000101
    MBR: 1111111111111111
   
Micro-instruction 24: rd; The read cycle is completed.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 0100000000001010
    MAR:     000000000101
    MBR: 0000000000000011
   
Note that the contents of address 5 are '3', and the MBR's contents are now 3.

Micro-instruction 25: mar=mbr&amask;rd;goto 5; The MAR is set to MBR AND'ed with the AMASK (isolating an address). A read cycle is begun, and the next microinstruction to be executed is #5.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 0100000000001010
    MAR:     000000000011
    MBR: 1111111111111111
   
Micro-instruction 5: tir:=lshift(tie);rd;if n goto 10; The TIR is left shifted, the read cycle is finished, and another goto check is performed.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 1000000000010100
    MAR:     000000000011
    MBR: 0000000000010001
   
Micro-instruction 10: tir=lshift(tir);if n goto 12; The TIR is left shifted again, and another goto check is performed.
    PC:                 1
    AC:                 0
    IR:  1010000000000101
    TIR: 0000000000101000
    MAR:     000000000011
    MBR: 0000000000010001
   
Micro-instruction 11: ac=ac+mbr;goto 0; The accumulator's contents are added to the contents of the MBR, and we're ready for the next instruction.
    PC:                 1
    AC:  0000000000010001
    IR:  1010000000000101
    TIR: 0000000000101000
    MAR:     000000000011
    MBR: 0000000000010001
   
This macro-instruction is now completed, and the cycle begins again.The objective was accomplished, that is, the accumulator now contains 0 plus the contents of the address stored in address 5 (i.e. 17).


Congratulations! If you understood all of that, you've completed your lesson on the inner workings of a computer. If you haven't done so already, check out the Java applet that simulates what was just talked about here. Try writing your own macro-programs, or just look at some of the examples, but what ever you do, have fun. If some of that seemed a little over your head, don't worry too hard. This is actually college graduate level material.
[Return to questions list|| See the Applet|| Home|| Index and Glossary]
For comments or suggestions, write to us.