Title: SUPER SIMPLE CPU
1SUPER SIMPLE CPU
2Super Simple CPU
- A hypothetical machine designed to contain the
important features of real computers that we want
to illustrate
3Features in Super Simple CPU
4Features in Super Simple CPU
- The memory unit is made up of 16 cells.
- Each cell consists of 16 bits (2 bytes)
- Registers/Status Bits
- The program counter (PC) (contains the address
of the next instruction to be executed) - The instruction register (IR) (contains a copy
of the instruction being executed) - The accumulator (ACC register)
5Instruction Format
- Instructions consist of 16 bits.
- The first 4 bits are operation code (opcode). It
specifies which instruction is to be carried out. - The rest of bits represent an operand.
opcode operand
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
6Opcodes
- Binary Mnemonic Short
Explanation - 1111 STP Stop the
computer - 0001 ADD Add
accumulator to operand - 0010 SUB Subtract
operand from accumulator - 0011 LOD Load memory
cell into accumulator - 0100 LDI Load
immediate into accumulator - 0101 STO Store
accumulator into memory cell - 0110 INP Input value
and store into accumulator - 0111 OUT Output the
value from accumulator - 1000 JMP Jump to
instruction - 1001 JNG Jump to
instruction if accumulatorlt0 - 1010 JZR Jump to
instruction if accumulator0
7Operands
- The operand can be many different things
depending upon which opcode it is used with. - It is the address of a memory cell, used by ADD,
SUB, LOD, STO - It is 12-bit constant used by LDI
- Jumping instructions JMP, JNG, JZR use 12-bit
operand as the value of PC.
8ADD Operation
opcode operand address of
data
0 0 0 1 0 0 0 0 0 0 0 0 1
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Add a value stored at memory address given by the
operand to the current value stored at the
accumulator. - The sum is stored at the accumulator.
9 SUB Operation
opcode operand address of
data
0 0 1 0 0 0 0 0 0 0 0 0 1
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Subtract a value stored at memory address given
by the operand from the current value stored at
the accumulator. - The result is stored at the accumulator.
10 LOD Operation
opcode operand address of
data
0 0 1 1 0 0 0 0 0 0 0 0 1
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Load a value stored at memory address given by
the operand to the accumulator.
11 STO Operation
opcode operand address of
data
0 1 0 1 0 0 0 0 0 0 0 0 1
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Store a value at the accumulator to memory
address given by the operand.
12 LDI Operation
opcode operand value
0 1 0 0 0 0 0 0 0 0 0 0 1
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Load to the accumulator a value given by the
operand.
13 JMP Operation
opcode operand address of
instruction
1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Set the Program Counter to a value given by the
operand. - Next instruction to execute is stored at the
address given by the operand.
14 JNG Operation
opcode operand address of
instruction
1 0 0 1 0 0 0 0 0 0 0 0 0
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Set the Program Counter to a value given by the
operand only if the current value of the
accumulator is negative. - Otherwise the next instruction will be executed.
15 JZR Operation
opcode operand address of
instruction
1 0 1 0 0 0 0 0 0 0 0 0 0
0 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
- Set the Program Counter to a value given by the
operand only if the current value of the
accumulator is zero. - Otherwise the next instruction will be executed.
16A Program Example
17Difficulties of Machine Language
- Writing and reading binary numbers is error prone
and difficult. - Remembering operations as binary numbers is
unintuitive. - Converting data and addresses to binary form is
not fun. - Numeric addresses make it difficult to modify
programs.
18Assembly Language
- There is one assembly language instruction per
machine language instruction. - Mnemonic codes are used instead of opcodes.
- Memory addresses are encoded symbolically using
identifiers. - Pseudo-operations do not create machine
instructions. - NUM DAT 0 instructs the assembler to change
the decimal 0 into binary, store it to a memory
cell, and associate identifier NUM to the address
of this cell.
19Mnemonic Codes
- Binary Mnemonic Short
Explanation - 1111 STP Stop the
computer - 0001 ADD Add
accumulator to operand - 0010 SUB Subtract
operand from accumulator - 0011 LOD Load memory
cell into accumulator - 0100 LDI Load
immediate into accumulator - 0101 STO Store
accumulator into memory cell - 0110 INP Input value
and store into accumulator - 0111 OUT Output the
value from accumulator - 1000 JMP Jump to
instruction - 1001 JNG Jump to
instruction if accumulatorlt0 - 1010 JZR Jump to
instruction if accumulator0
20Program Example
21Example 1
INP STO A
INP STO B INP
STO C LOD A ADD B
SUB C OUT
STP A DAT 0 B DAT 0 C
DAT 0
- 1) Input three numbers a,b, and c.
- 2) Compute ab-c and output the result.
22 Example 2
INP STO X
INP STO Y SUB X
JZR FIRST LDI 1
ADD Y STO Y OUT
JMP END FIRST LDI 3 ADD X
STO X END LOD X OUT
STP X DAT 0 Y DAT 0
- Input x and y
- If x y then
- add 3 to x
- else
- add 1 to y
- output y
- output x
if xy JUMP
23Example 3
Input 100 numbers Compute their sum Output the
result
START LDI 100 SUB COUNT
JNG END INP
ADD SUM STO SUM
LDI 1 ADD COUNT
STO COUNT JMP
START END LOD SUM
OUT STP COUNT DAT 1 SUM
DAT 0
Need another number?
if count gt 100 then done
Initialize count to 1 And sum to 0