Introduction to ICE

Processor

topic

- machine organisation
- machine language
- machine execution cycle

(next week)
- simple binary operations
- logic gates

Machine organisation

components

- memory, random access, it takes the same amount of time to reach anywhere in the memory.  Memory operations: read, write.  Must present the "address" to the memory to specify to location.

- functional units, perform operations on data, data is considered to be "binary".  There are two states: true, false (on, off; or 1, 0).  The signal such as voltage, current, can be used to represent the states.  Such as 5 volts as 1, 0 volt as 0.

- registers, storing data.

- ALU, arithmetic logic unit.

- multiplexors, the selector, choosing one of many inputs to be the output.

- wires, connecting components.  As there are many bits to represent a quantity, there are many wires. Each wire carries one bit.  Present technology produces many commercial processors with 32-bit. A newer one is 64-bit.  It means the "natural" size of a piece of data in these machines has that many bits.  The "embedded" computers (a small processor inside electrical appliances) are usually small bit-size, 4-bit or 8-bit. The cell phone nowaday usually has 32-bit processor with low power consumption.

Hypothetical computer  (S4)

            
           address              +1
        M  <--- MAR -- S <---  PC <-- arg
       | ^             |<--- arg
  read | | write       |<-    
       v |               |
    -- MIU <-------------+
    |                    |
    +-----> X --->|  F   |
    |             |  |   |
   IR             ALU----+
    |             |      | Tbus
    --> T -> AC ->|      |
    +-->|                |
    |                    |
    +--------------------+

<figure to be upgrade shortly>
<this much I can do with "notepad" :-) >

M    memory
MIU  memory interface unit
MAR  memory address register
IR   instruction register
X    temporary register
AC   accumulator register
PC   program counter
ALU  arithmetic logic unit
F    flag register
S,T  multiplexors

The memory address register stores the current address to access the memory.  The memory interface unit is a circuit to control the memory operations: read and write.  The instruction register stores the current instnruction.  The program counter stores the current address of the instruction.  The temporary register stores the value reading from the memory to be the input of the ALU.  The arithmetic logic unit performs many "computation" operations such as: add, subtract, logical operations.  The flag register stores the result of the logical operation of the ALU.  It is used by the instruction that alter the "control flow" of a program.  Tbus is the name of the output wire of the ALU. It feeds to a number of functional units.  The "T" multiplexor selects either IR or Tbus to AC.  The "S" multiplexor selects amongs three inputs: PC, arg and Tbus to feed to MAR. The program counter has one special operation: +1, means "increment" the counter. This is used to step the program counter to point to the next instruction.

The instruction register has 32 bits.  It has the format as follows.

bit number  31..24 23..0
              op    arg

op is the operational code, 8-bit
arg is the argument, 24-bit

The central internal storage of this computer is the AC (accumulator).  This type of structure is called "accumulator machine".  (There are many other types such as register-based, stack-based machines).  

The structure shown above is called "data path".  There is one unit missing, which orchestrates the movement of data between these units. It is called "control unit". The control unit issues signals to activate data movement through these units to perform the desired sequences of operations.

The structure of a computer reflexes how it can be programmed.  The possible operations are constraint by the type of functional units and their connections.  The structure shown above is not arbitrary.  It is a typical example of an actual processor. Only that this hypothetical computer is a very much simplified version of a real processor.  The actual circuits can be built according to this structure to really work as a computer.   

This conclude the section on the machine organisation. This is the "hardware" or the "body" of a computer.  What is needed is its "soul". 

Machine language

The "language" of a processor is also dependent on its "structure".  The "human" programming language is usually said to be a "high level" language.  The "machine" language is the one that directly reflex what can be "compute" on a particular data path. Conforming to the format of the instruction register, the first 8 bits are the operational code.  The right most 24 bits are the argument of the instruction. 

We define a set of instructions on our hypothetical machine.  Each instruction has the size of one memory location (one word so to speak).  Here is the list of the available instructions.

arithmetic:  add, sub
logic:         equal-zero, not-equal-zero, less-than-or-equal-zero
data:          load, store, load-constant
control:      jump, jump-if-true, jump-if-false

We use "mnemonics" to write this language.  This style of programming is called, assembly language programming.  We write "op.arg" where op is the mnemonic of the instruction, arg is the name of a location in the memory.  The name of a location is the memory is considered to be a "variable" in any "human" programming language.

Here is the table showing the code of each instruction, its mnemonics and its meaning. 

The notation M[ads] means the memory at the location ads. "ads" is called the "address". It can range over the number of available memory.  For a typical 32-bit processor, the range is 2^32 (2 to the power of 32) words (a lot !, 4G words).

The notation "a -> b"  means transferring the value of the register a to the register b.

add:                      1, add.x,  AC = M[x] + AC
sub:                      2, sub.x,  AC = M[x] - AC
equal-zero:               3, eq0.x,  F = (M[x] == 0)
not-equal-zero:           4, ne0.x,  F = (M[x] != 0)
less-than-or-equal-zero:  5, le0.x,  F = (M[x] <= 0)
load:                     6, ld.x,   M[x] -> AC
store:                    7, st.x,   AC -> M[x]
load-constant:            8, lc.x,   x -> AC
jump:                     9, jmp.x,  x -> PC
jump-if-true:            10, jt.x,   if (F != 0) then x -> PC
jump-if-false:           11, jf.x,   if (F == 0) then x -> PC

Example

Here are some simple programs:

let A, B, C be variables.  Their locations in the memory are: A is 100, B is 101, C is 102

The very first program  do  C = A + B

  ld.A
  add.B
  st.C

Now see how to deal with a constant   do  C = A - 2

  lc.2
  sub.A
  st.C

Be careful about the sequence of loading AC.  Some operator is not commutative, for example a subtraction, (a - b) != (b - a).

Now we can do a more ambitious program using "iteration" (repeating action).  We use the notation ":label" to specify the location for the control instructions. 

  do sum from 1 to 10

We use a number of variables, SUM stores the result, N is the value 10..1. We start by setting SUM = 0, N = 10. Add N to SUM and decrement N. Do it ten times.  Let SUM is 103, N is 104

:toten
  lc.0
  st.SUM
  lc.10
  st.N
:loop
  le0.N
  jt.exit
  ld.SUM
  add.N
  st.SUM
  lc.1
  sub.N
  st.N
  jmp.loop
:exit

The  "; ...." is the notation for "commenting" the program.  The comment is ignored by the software tool used to translate this program into an actual executable code.  This tool is called, an assembler.  For example, you can write:

le0.N   ; if N <= 0

The text "; if N <=0 " will be ignore by the assembler.  The comment is used to convey the meaning of a program to human.  I usually wrote comments to help myself to remember what the program does.  When I have to change some part of a program after it has been written many months ago, comments are the key to help me to understand what have been done.

Machine execution cycle

(how machines perform operations)

A processor runs a program by repeatingly getting an instruction from the memory, this is called "fetching an instruction", then "decode" what instruction it is by looking at the opcode bit (in our computer, the first 8 bits of an instruction), then performs the operation according to that opcode, such as "add", "sub", etc.  The notation we will be used to explain the movement of data in the data path is:

A -> B                denotes data from a source  A (a register or a wire or a functional unit) to a destination B.
Mread, Mwrite   memory read, memory write operations
AC = X + AC    ALU operation with A and X
arg                     is the last 24 bits of the instruction register, designate an argument of an instruction

repeat
  fetch an instruction
  decode
  execute

fetch an instruction
  PC -> MAR    (1)
  Mread -> IR  (2)
  PC+1         (3)

execute
  do appropriate actions

add
  arg -> MAR   (4)
  Mread -> X   (5)
  AC = X + AC  (6)

sub
  arg -> MAR
  Mread -> X
  AC = X - AC

eq0
  arg -> MAR
  Mread -> X
  F = (X == 0)?

...

ld
  arg -> MAR
  Mread -> X
  X -> AC

st
  arg -> MAR
  AC -> Tbus (via ALU)
  Mwrite

lc
  arg -> AC

jmp
  arg -> PC

jt
  if F != 0  arg -> PC

jf
  if F == 0  arg -> PC

When fetching an instruction, the PC will be incremented to point to the next instruction.  The control instruction (jmp, jt, jf) change PC. 

An example how the processor executes the instuction "add.100" where 100 is the location of the memory.  The processor fetches the instruction "add.100" by the steps (1), (2), (3) then decode and performs the steps (4), (5), (6).(assuming the decode takes no cycle).  The round continue with PC at the next instruction, and so on.

If we consider a step takes one clock cycle (the speed of a processor is detemined by its main clock, such as 1GHz, 2 GHz), then the "add" instruction takes 6 cycles.   If the clock is 1GHz then each cycle is 1 ns (nano second, 10^-9 sec.).  The "add" instruction will take 6 ns. to complete. 

Note

I will be hospitalised for a month starting today, so my lecture note has to stop short here.  That includes the tools to try out running our hypothetical computer (a simulator and an assembler).  I will have to be postponed them until I come back.  For students who are interested please have a look at my lecture on Assembly language.  There are a lot of lectures and tools there.  The processor and the assembly language are not exactly like the one we lectured, but they are similar. 

10 September 2007