Design and Implementation of Simple As Possible Computer (SAP-1)
Design and Implementation of Simple As Possible Computer (SAP-1)
Design and Implementation of Simple As Possible Computer (SAP-1)
www.iiu.edu.pk 6/15/20
SAP-1 Introduction
2
www.iiu.edu.pk 6/15/20
3
SAP-1
Block Diagram
www.iiu.edu.pk 6/15/20
Main Features
4
Simple-As-Possible.
One output device with 8 LEDs
16 bytes of read only memory.
5 instructions
3 with 1 operand,
2 with implicit operands.
Accumulator Architecture
Accumulator, Out Register,
B Register, Memory Address Register (MAR)
Instruction Register (IR).
www.iiu.edu.pk 6/15/20
Architecture
5
www.iiu.edu.pk 6/15/20
6
www.iiu.edu.pk 6/15/20
Program Counter
7
www.iiu.edu.pk 6/15/20
Program Counter
8
www.iiu.edu.pk 6/15/20
Input and Memory Address Register (MAR)
9
www.iiu.edu.pk 6/15/20
10
www.iiu.edu.pk 6/15/20
The RAM
11
www.iiu.edu.pk 6/15/20
Intel Hex File Format
www.iiu.edu.pk 6/15/20
14
www.iiu.edu.pk 6/15/20
Adder/Subtractor
15
www.iiu.edu.pk 6/15/20
16
www.iiu.edu.pk 6/15/20
18
www.iiu.edu.pk 6/15/20
B Register
19
www.iiu.edu.pk 6/15/20
20
www.iiu.edu.pk 6/15/20
Output Register
21
www.iiu.edu.pk 6/15/20
22
www.iiu.edu.pk 6/15/20
Binary Display
23
www.iiu.edu.pk 6/15/20
Controller Sequencer
24
T6 T5 T4 T3 T2 T1
www.iiu.edu.pk 6/15/20
Ring Counter Timing Diagram
26
www.iiu.edu.pk 6/15/20
27
www.iiu.edu.pk 6/15/20
Control Matrix
28
www.iiu.edu.pk 6/15/20
LDA Instruction
31
www.iiu.edu.pk 6/15/20
ADD Instruction
32
ADD 9H means “add the data of memory location 9H with data
of accumulator and save the result in accumulator.
Suppose No. 2 is in the accumulator and No.3 is in memory
location 9H. Then ACC =0000 0010, RAM[9] = 0000
0011
During the execution of ADD 9H,
First data at RAM address 9 is loaded into the B register to get B = 0000 0011
and instantly the adder/subtracter forms the sum of A and B SUM = 0000 0101
Second, this sum is loaded into the accumulator to get ACC = 0000
0101
Similarly, the execution of ADD FH adds data at RAM address 15
to the accumulator and save the answer back in accumulator
overwriting the previous value.
The negative numbers are stored in 2’s complement form.
www.iiu.edu.pk 6/15/20
SUB Instruction
33
www.iiu.edu.pk 6/15/20
HLT Instruction
35
www.iiu.edu.pk 6/15/20
Memory Reference Instructions
36
www.iiu.edu.pk 6/15/20
Op Codes of SAP-1
37
To load instruction and data words into the SAP-1 memory , we
have to use some kind of code that the computer can interpret.
The number 0000 stands for LDA, 0001 for ADD, 0010 for SUB,
0000 for OUT, and 1111 for HLT.
Because this code tells the computer which operation to
perform, it is called an operation code (op code).
Assembly language involves working TABLE 2, SAP-1 OP CODES
Mnemonics Op Code
with mnemonics when writing a
LDA 0000
program.
ADD 0001
Machine language involves
SUB 0010
working with strings of 0s and 1s. OUT 1110
HLT 1111
www.iiu.edu.pk 6/15/20
Program in Assembly Program in Machine Language
Address Contents Address Contents in Binary Contents in Hexadecimal
0H LDA 9H 0000 0000 1001 09H
1H ADD AH 0001 38
0001 1010 1AH
2H ADD CH 0010 0001 1100 1CH
3H SUB BH 0011 0010 1011 2BH
4H OUT 0100 1110 1111 EFH
5H HLT 0101 1111 1111 FFH
6H FFH 0110 1111 1111 FFH
7H FFH 0111 1111 1111 FFH
8H FFH 1000 1111 1111 FFH
9H 10H 1001 0001 0000 10H
AH 18H 1010 0001 1000 18H
BH 14H 1011 0001 0100 14H
CH 20H 1100 0010 0000 20H
DH FFH 1101 1111 1111 FFH
EH FFH 1110 1111 1111 FFH
FH
www.iiu.edu.pkFFH 1111 1111 1111 FFH 6/15/20
The 8080 and 8085 Microprocessors
39
www.iiu.edu.pk 6/15/20
Fetch Cycle
40
The control unit is the key to a computer's automatic
operation. The control unit generates the control words
that fetch and execute each instruction.
While each instruction is fetched and executed, the
computer passes through different timing states (T states),
time intervals during which register contents change.
Ring Counter has an output of
T = T6T5T4T3T2T1
At the beginning of a computer run, the ring word is
T = 00 0001 = T1
Successive clock pulses produce, ring words of
www.iiu.edu.pk 6/15/20
Ring Counter
41
Successive clock pulses produce, ring words of
T = 000010 = T2
T = 000100 = T3
T = 001000 = T4
T = 010000 = T5
T = 100000 = T6
Then, the ring counter resets to 00 00 01, and the cycle
repeats.
Each ring word represents one T state.
The initial state T1 starts with a negative clock edge and ends
with the next negative clock edge.
www.iiu.edu.pk 6/15/20
Ring Counter
42
During this T state, the T1 bit out of the ring counter is
high.
During the next state, T2 is high; the following state has a
high T3; then a high T4; and so on.
The ring counter produces six T states. Each instruction
is fetched and executed during these six T states.
A positive CLK edge occurs midway through each T state.
www.iiu.edu.pk 6/15/20
Address State (T = 00 0001 = 1 = T1)
43
The T1 state is called the address state because the
address in the program counter (PC) is transferred to the
memory address register (MAR) during this state.
During the address state, EP and L'M are active; all other
control bits are inactive. This means that the controller-
sequencer is sending out a control word of 5E3H during
this state
CON C P E P L M CE L I E I L A E A SU EU L B L O
= 0 1 0 1 1 1 1 0 0 0 1 1
= 5 E 3
www.iiu.edu.pk 6/15/20
Increment State (T = 00 0010 = 2 = T2)
44
The T1 state is called the increment state because the
program counter is incremented.
During the increment state, the controller-sequencer is
producing a control word of BE3H
Only the CP bit is active in this state.
CON C P E P L M CE L I E I L A E A SU EU L B L O
= 1 0 1 1 1 1 1 0 0 0 1 1
= B E 3
www.iiu.edu.pk 6/15/20
Memory State (T = 00 0100 = 4 = T3)
45
The T3 state is called the memory state because the
addressed RAM instruction is transferred from the
memory to the instruction register.
The only active control bits during this state are CE' and
LI , and the word out of the controller-sequencer is 263H
CON C P E P L M CE L I E I L A E A SU EU L B L O
= 0 0 1 0 0 1 1 0 0 0 1 1
= 2 6 3
www.iiu.edu.pk 6/15/20
Fetch Cycle
46
The address, increment, and memory states are called the fetch cycle of
SAP-l.
During the address state, EP and LM arc active; this means that the
program counter sets up the MAR via the W bus.
A positive clock edge occurs midway through the address state; this
loads the MAR with the contents of the PC.
During the increment state, CP is the only active control bit.
This sets up the program counter to count positive clock edges.
Halfway through the increment state, a positive clock edge hits the
program counter and advances the count by 1.
During the memory state, CE' and L'I are active. The addressed RAM
word sets up the instruction register via the W bus. Midway through
the memory state, a positive clock edge loads the instruction register
with the addressed RAM word.
www.iiu.edu.pk 6/15/20
Execution Cycle
47
The next three states (T4, T5, and T6) are the execution
cycle of SAP-1.
The register transfers during the execution cycle
depend on the particular instruction being executed.
For instance. LDA 9H requires different register
transfers than ADD BH.
What follows are the control routines for different
SAP-1 instructions.
www.iiu.edu.pk 6/15/20
Micro Instructions
48
www.iiu.edu.pk 6/15/20
Macro Instructions
49
The instructions we have been programming with (LDA,
ADD, SUB, . . .) are sometimes called macro-instructions to
distinguish them from micro-instructions.
Each SAP-1 macroinstruction is made up of three
microinstructions. For example, the LDA
macroinstruction consists of the three microinstructions
shown in the next Table.
This table shows the SAP-1 macro-instruction and the
micro-instructions needed to carry it out.
www.iiu.edu.pk 6/15/20
Fetch and Execute Cycle of SAP-1
Macro Inst. T State Micro Operation Active CON
All T1 MAR ← PC L'M, EP 5E3H
Instructions 50
T2 PC← PC+1 CP BE3H
T3 IR ← RAM[MAR] CE', L‘I 263H
LDA T4 MAR ← IR(3…0) L'M, E‘I 1A3H
T5 ACC ← RAM[MAR] CE', L'A 2C3H
T6 None None 3E3H
ADD T4 MAR ← IR(3…0) L'M, E‘I 1A3H
T5 B ← RAM[MAR] CE', L'B 2E1H
T6 ACC ← ACC+B L'A, EU 3C7H
SUB T4 MAR ← IR(3…0) L'M, E‘I 1A3H
T5 B ← RAM[MAR] CE', L'B 2E1H
T6 ACC ← ACC – B L'A, SU, EU 3CFH
OUT T4 OUT ← ACC EA, L'O 3F2H
T5 None None 3E3H
T6 None None 3E3H
HLT
www.iiu.edu.pk T4 None HLT ' 263H 6/15/20
51
0011
0001
0000
0010
0100 0000 1000
SAP-1
0000 1000
Simulation
of Program
1111
0001 1111
1001
0101
1010
0011
LDA 9H 0000
1110
ADD AH 1010
1001
OUT
0000
0001
1110
1111
HLT 08
Computer T321654
www.iiu.edu.pk Halted 6/15/20
That’s all
www.iiu.edu.pk 52 6/15/20