Loading lessons...
Input-Output, Interrupt & Design of the Basic Computer (Control Gates and AC Logic)
Input-Output, Interrupt & Design of the Basic Computer (Control
Gates and AC Logic)
This lesson completes the basic computer. First the input-output registers, flags and instructions, then the program interrupt that lets I/O run without wasting processor time. With every register transfer statement now known, we finish with the actual design: the logic gates that drive the register control inputs, the bus select encoder and the accumulator.
1. Input-Output Configuration
The basic computer talks to one terminal (a keyboard for input and a printer for output) through a serial interface.
Input-output configuration
- INPR (8-bit input register) receives an alphanumeric character code from the keyboard.
- OUTR (8-bit output register) holds a character for the printer.
- FGI (input flag): set to 1 when a new character is in INPR; cleared when the computer takes it.
- FGO (output flag): 1 when OUTR is free to accept a new character; cleared when the computer loads OUTR, set again when the printer has printed it.
Input: a key press puts the code in INPR and sets FGI = 1. While FGI = 1 the keyboard cannot change INPR. The computer checks FGI; if it is 1, it moves INPR into AC(0-7) and clears FGI.
Output: the computer checks FGO; if it is 1, it moves AC(0-7) into OUTR and clears FGO. The printer prints the character and sets FGO = 1 again.
1.1 Input-output instructions
I/O instructions are recognised by D7 I T3 (opcode 111, I = 1). Let p = D7 I T3 and Bi = IR(i):
| Symbol | Hex | Control | Register transfer | Meaning |
|---|---|---|---|---|
| (all) | p | SC ← 0 | clear SC | |
| INP | F800 | p B11 | AC(0-7) ← INPR, \ FGI ← 0 | input a character |
| OUT | F400 | p B10 | OUTR ← AC(0-7), \ FGO ← 0 | output a character |
| SKI | F200 | p B9 | if (FGI = 1) then (PC ← PC + 1) | skip on input flag |
| SKO | F100 | p B8 | if (FGO = 1) then (PC ← PC + 1) | skip on output flag |
| ION | F080 | p B7 | IEN ← 1 | interrupt enable on |
| IOF | F040 | p B6 | IEN ← 0 | interrupt enable off |
2. Program Interrupt
With programmed I/O, the program checks the flag in a loop (SKI, BUN back) until it is set. Because I/O devices are far slower than the processor, almost all of that time is wasted.
The clock is 1 MHz and the wait loop is SKI followed by BUN (back to SKI). The keyboard delivers 10 characters per second. How many loop passes are wasted per character?
- SKI is register/I-O type: 4 cycles. BUN: 5 cycles. One pass = 9 cycles = 9 µs.
- Time between characters = 1/10 s = 100 ms = 100 000 µs.
- Passes per character = 100 000 / 9 ≈ 11 111.
The alternative is the interrupt: the computer runs another program and the I/O device interrupts it when a flag is set.
- IEN (interrupt enable flip-flop) is set by ION and cleared by IOF; the program decides whether it can be interrupted.
- R (interrupt flip-flop) marks that an interrupt cycle must run instead of the next instruction cycle.
At any time outside T0, T1, T2, if interrupts are enabled and a flag is up, R is set:
(Setting R only after T2 makes sure an instruction in progress is not disturbed during its fetch.) After the current instruction finishes and SC returns to 0, the control checks R: R = 0 starts a normal instruction cycle; R = 1 starts the interrupt cycle.
2.1 The interrupt cycle
The interrupt cycle is a hardware BSA to address 0: it saves the return address in location 0 and branches to location 1.
So the fetch phase is now written with R': R'T0: AR ← PC, R'T1: IR ← M[AR], PC ← PC + 1, R'T2: ldots
Interrupt cycle: flowchart and memory
Location 1 normally holds a BUN to the I/O service program. That program saves the processor registers, checks the flags, services the device, restores the registers, turns interrupts back on with ION, and returns with BUN 0 I (indirect through location 0, which holds the return address). IEN is cleared during the interrupt cycle so the service program itself is not interrupted.
Location 1 holds 0 BUN 1120. An interrupt is requested while the instruction at 255 is executing (IEN = 1, FGI = 1). Find PC, M[0], IEN and R at each stage.
- During the instruction at 255, at some T3 or later, R ← 1. When it finishes, PC = 256.
- RT0: AR = 0, TR = 256. RT1: M[0] = 256, PC = 0. RT2: PC = 1, IEN = 0, R = 0.
- The instruction at 1 (BUN 1120) runs: PC = 1120, and the I/O program executes.
- The program ends with ION, then BUN 0 I: EA = M[0] = 256, PC = 256. The interrupted program continues.
3. Design of the Basic Computer
The complete hardware is:
- a memory unit of 4096 words × 16 bits,
- nine registers: AR, PC, DR, AC, IR, TR, OUTR, INPR, SC,
- seven flip-flops: I, S, E, R, IEN, FGI, FGO,
- two decoders (3 × 8 for the opcode, 4 × 16 for timing),
- a 16-bit common bus,
- control logic gates,
- an adder and logic circuit connected to the input of AC.
The control logic gates are found by a simple rule: collect every statement that changes a given register or flip-flop, and OR together the control functions that need each of its inputs (LD, INR, CLR).
3.1 Control of AR
From all the RTL statements, AR changes in these places:
| Control function | Statement |
|---|---|
| R' T0 | AR ← PC |
| R' T2 | AR ← IR(0-11) |
| D7' I T3 | AR ← M[AR] |
| R T0 | AR ← 0 |
| D5 T4 | AR ← AR + 1 |
The first three load AR from the bus, so
Control gates for AR
Derive the logic for IEN, built from a JK flip-flop.
- Statements that change IEN: p B7: IEN ← 1; p B6: IEN ← 0; R T2: IEN ← 0.
- J sets: J = p B7.
- K clears: K = p B6 + R T2.
3.2 Memory read and write
3.3 Control of the common bus
Seven sources can drive the bus. Let x1, ldots, x7 be 1 when AR, PC, DR, AC, IR, TR or memory must be on the bus. An encoder turns them into the select code S2 S1 S0:
| x1 | x2 | x3 | x4 | x5 | x6 | x7 | S2 S1 S0 | Register on the bus |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 000 | none |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 001 | AR |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 010 | PC |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 011 | DR |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 100 | AC |
| 0 | 0 | 0 | 0 | 1 | 0 | 0 | 101 | IR |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 110 | TR |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 111 | memory |
Each xi is found by searching the RTL for statements that read that register onto the bus:
| Bus source | Gate logic | From the statements |
|---|---|---|
| x1 (AR) | D4 T4 + D5 T5 | PC ← AR in BUN and BSA |
| x2 (PC) | T0 + D5 T4 | AR ← PC, TR ← PC, M[AR] ← PC |
| x3 (DR) | D6 T6 | M[AR] ← DR in ISZ |
| x4 (AC) | D3 T4 + p B10 | STA and OUT |
| x5 (IR) | R' T2 | AR ← IR(0-11) |
| x6 (TR) | R T1 | M[AR] ← TR |
| x7 (memory) | same as Read | every memory read |
3.4 Design of the accumulator logic
AC is changed by AND, ADD, LDA (from DR), INP (from INPR), and the register-reference instructions CLA, CMA, CIR, CIL, INC. All the values that need a load pass through the adder and logic circuit, whose 16 stages take AC and DR (and INPR for bits 0-7) as inputs.
| Control function | Statement | AC input used |
|---|---|---|
| D0 T5 | AC ← AC wedge DR | LD (AND gates) |
| D1 T5 | AC ← AC + DR | LD (adder) |
| D2 T5 | AC ← DR | LD (transfer DR) |
| p B11 | AC(0-7) ← INPR | LD (transfer INPR) |
| r B9 | AC ← overline{AC} | LD (complement) |
| r B7 | AC ← shr AC, \ AC(15) ← E | LD (shift right) |
| r B6 | AC ← shl AC, \ AC(0) ← E | LD (shift left) |
| r B11 | AC ← 0 | CLR |
| r B5 | AC ← AC + 1 | INR |
Each of the seven LD terms also selects which operation the adder and logic circuit performs: one stage i of that circuit is an OR of seven AND gates (AC(i) ∧ DR(i) with AND, the full-adder sum with ADD, DR(i) with LDA, INPR(i) with INP, AC(i)' with COM, AC(i+1) with SHR, AC(i−1) with SHL).
Which control inputs and bus code are active at D5 T4 (BSA) and at D1 T5 (ADD)?
- D5 T4: M[AR] ← PC, AR ← AR + 1. PC on the bus (x2: S2 S1 S0 = 010), memory Write, INR(AR).
- D1 T5: AC ← AC + DR, E ← Cout. No bus transfer (the adder reads DR directly): S = 000, LD(AC) with the adder selected, E loaded from the carry.
Derive LD, INR and CLR for PC.
- LD (from the bus): D4 T4: PC ← AR and D5 T5: PC ← AR. So LD(PC) = D4 T4 + D5 T5.
- CLR: R T1: PC ← 0. So CLR(PC) = R T1.
- INR: the fetch, the interrupt cycle, ISZ and every skip: INR(PC) = R' T1 + R T2 + D6 T6 (DR = 0) + r B4 AC(15)' + r B3 AC(15) + r B2 (AC = 0) + r B1 E' + p B9 FGI + p B8 FGO.
4. Verilog: The Control Gates
The module below is the gate logic of this section, written as Boolean equations (AR, AC, memory and the bus encoder). The testbench applies the IR value and timing step of several RTL statements and prints which control inputs are 1:
// Control gates of the basic computer: AR and AC control inputs, memory
// read/write and the bus select encoder, written straight from the RTL
module control_gates (
input [7:0] D,
input [15:0] T,
input I,
input R,
input [11:0] B,
output ldAR, inrAR, clrAR,
output ldAC, inrAC, clrAC,
output rd, wr,
output [2:0] sel
);
wire r = D[7] & ~I & T[3];
wire p = D[7] & I & T[3];
assign ldAR = ~R & T[0] | ~R & T[2] | ~D[7] & I & T[3];
assign clrAR = R & T[0];
assign inrAR = D[5] & T[4];
assign ldAC = D[0] & T[5] | D[1] & T[5] | D[2] & T[5] | p & B[11]
| r & B[9] | r & B[7] | r & B[6];
assign inrAC = r & B[5];
assign clrAC = r & B[11];
assign rd = ~R & T[1] | ~D[7] & I & T[3] | (D[0] | D[1] | D[2] | D[6]) & T[4];
assign wr = D[3] & T[4] | D[5] & T[4] | D[6] & T[6] | R & T[1];
// which register drives the bus (x1 = AR ... x7 = memory)
wire x1 = D[4] & T[4] | D[5] & T[5];
wire x2 = T[0] | D[5] & T[4];
wire x3 = D[6] & T[6];
wire x4 = D[3] & T[4] | p & B[10];
wire x5 = ~R & T[2];
wire x6 = R & T[1];
wire x7 = rd;
// 8 x 3 encoder
assign sel[0] = x1 | x3 | x5 | x7;
assign sel[1] = x2 | x3 | x6 | x7;
assign sel[2] = x4 | x5 | x6 | x7;
endmodule
module tb;
reg [15:0] ir;
reg [3:0] sc;
reg R;
wire [7:0] D = 8'b1 << ir[14:12];
wire [15:0] T = 16'b1 << sc;
wire ldAR, inrAR, clrAR, ldAC, inrAC, clrAC, rd, wr;
wire [2:0] sel;
control_gates u (D, T, ir[15], R, ir[11:0], ldAR, inrAR, clrAR,
ldAC, inrAC, clrAC, rd, wr, sel);
task step(input [15:0] w, input [3:0] t, input rr, input [8*24:1] name);
begin
ir = w;
sc = t;
R = rr;
#1 $display("bus=%b rd=%b wr=%b AR(LD,INR,CLR)=%b%b%b AC(LD,INR,CLR)=%b%b%b %0s",
sel, rd, wr, ldAR, inrAR, clrAR, ldAC, inrAC, clrAC, name);
end
endtask
initial begin
step(16'h0000, 0, 0, "R'T0 AR <- PC");
step(16'h0000, 1, 0, "R'T1 IR <- M[AR]");
step(16'h9104, 2, 0, "R'T2 AR <- IR(0-11)");
step(16'h9104, 3, 0, "ADD I, T3 AR <- M[AR]");
step(16'h9104, 4, 0, "ADD T4 DR <- M[AR]");
step(16'h9104, 5, 0, "ADD T5 AC <- AC + DR");
step(16'h3104, 4, 0, "STA T4 M[AR] <- AC");
step(16'h5104, 4, 0, "BSA T4 M[AR] <- PC");
step(16'h5104, 5, 0, "BSA T5 PC <- AR");
step(16'h6104, 6, 0, "ISZ T6 M[AR] <- DR");
step(16'h7800, 3, 0, "CLA");
step(16'h7020, 3, 0, "INC");
step(16'hF800, 3, 0, "INP");
step(16'h0000, 0, 1, "RT0 AR <- 0, TR <- PC");
step(16'h0000, 1, 1, "RT1 M[AR] <- TR");
end
endmoduleEach line matches the RTL: for example STA puts AC on the bus (100) and writes, BSA T4 puts PC on the bus (010), writes and increments AR, ADD T5 uses no bus and loads AC, and the interrupt cycle clears AR and then writes TR (110) into M[0]:
bus=010 rd=0 wr=0 AR(LD,INR,CLR)=100 AC(LD,INR,CLR)=000 R'T0 AR <- PC
bus=111 rd=1 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 R'T1 IR <- M[AR]
bus=101 rd=0 wr=0 AR(LD,INR,CLR)=100 AC(LD,INR,CLR)=000 R'T2 AR <- IR(0-11)
bus=111 rd=1 wr=0 AR(LD,INR,CLR)=100 AC(LD,INR,CLR)=000 ADD I, T3 AR <- M[AR]
bus=111 rd=1 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 ADD T4 DR <- M[AR]
bus=000 rd=0 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=100 ADD T5 AC <- AC + DR
bus=100 rd=0 wr=1 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 STA T4 M[AR] <- AC
bus=010 rd=0 wr=1 AR(LD,INR,CLR)=010 AC(LD,INR,CLR)=000 BSA T4 M[AR] <- PC
bus=001 rd=0 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 BSA T5 PC <- AR
bus=011 rd=0 wr=1 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 ISZ T6 M[AR] <- DR
bus=000 rd=0 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=001 CLA
bus=000 rd=0 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=010 INC
bus=000 rd=0 wr=0 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=100 INP
bus=010 rd=0 wr=0 AR(LD,INR,CLR)=001 AC(LD,INR,CLR)=000 RT0 AR <- 0, TR <- PC
bus=110 rd=0 wr=1 AR(LD,INR,CLR)=000 AC(LD,INR,CLR)=000 RT1 M[AR] <- TRKey points to remember
- INPR, OUTR (8 bits), flags FGI (input ready), FGO (output free). I/O instructions: p = D7 I T3.
- Interrupt: T0' T1' T2' (IEN)(FGI + FGO): R ← 1; cycle RT0, RT1, RT2 saves PC in M[0], jumps to 1, clears IEN. Return: BUN 0 I.
- Design rule: collect all statements that change a register; OR their control functions per input.
- LD(AR) = R'T0 + R'T2 + D7' I T3, CLR(AR) = RT0, INR(AR) = D5 T4.
- Bus encoder: S0 = x1 + x3 + x5 + x7, S1 = x2 + x3 + x6 + x7, S2 = x4 + x5 + x6 + x7.
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Draw the input-output configuration of the basic computer and explain the role of FGI and FGO. List the I/O instructions with their RTL. (10 Marks)
- Q2. What is a program interrupt? Draw the flowchart of the interrupt cycle and give its register transfers. Show memory before and after an interrupt. (10 Marks)
- Write: the R ← 1 condition, RT0 to RT2, M[0] holds the return address, BUN 0 I to return.
- Q3. Derive the control gate logic for AR and draw the gates. (5 Marks)
- Q4. Design the bus select encoder of the basic computer and derive x1 to x7. (10 Marks)
- Q5. Explain the design of the accumulator logic. Write LD, INR and CLR of AC. (5 Marks)