Lesson 25 +35 XP

Stored Program Organisation, Computer Registers & the Common Bus

Stored Program Organisation, Computer Registers & the Common Bus

Unit III puts the pieces of Units I and II (registers, counters, decoders, adders, memory) together into a complete computer. We follow M.

Morris Mano's basic computer: small enough to design completely, yet it has everything a real processor has. This lesson introduces the stored-program idea, the instruction format, the registers, and the common bus that connects them.

1. The Stored Program Concept

A computer's behaviour is set by a program: a sequence of instructions stored in memory. The stored-program (von Neumann) idea is that instructions and data sit in the same memory in binary, so a program can be loaded, changed and even treated as data.

An instruction code is a group of bits that tells the computer to perform an operation. It has two parts:

  • the operation code (opcode): which operation (add, load, branch, ...), and
  • an address (or other operand information): where the data is.

An opcode of n bits can specify up to 2n distinct operations.

Instructions and data share one memoryInstructions and data share one memory

The basic computer has a memory of 4096 words × 16 bits: an address needs log2 4096 = 12 bits, leaving 4 bits of a 16-bit instruction for the opcode and an addressing-mode bit.

2. Instruction Format and Addressing

Bit 15Bits 14 to 12Bits 11 to 0
I (addressing mode)opcode (3 bits)address (12 bits)
  • I = 0: direct address. The address field is the address of the operand.
  • I = 1: indirect address. The address field points to a memory word that holds the address of the operand. Indirect addressing needs one extra memory read.

The address actually used to reach the operand is the effective address (EA).

Direct and indirect addressingDirect and indirect addressing

SolvedExample 1 · Effective address

The instruction at address 22 is 0 ADD 457 and the one at address 35 is 1 ADD 300. Memory word 300 contains 1350. Find the effective address and the number of memory references of each instruction (including its fetch).

  1. Address 22, I = 0: EA = 457. References: fetch the instruction (1) + read the operand (1) = 2.
  2. Address 35, I = 1: read M[300] = 1350, so EA = 1350. References: fetch (1) + read the address (1) + read the operand (1) = 3.
AnswerEA = 457 with 2 references; EA = 1350 with 3 references
SolvedExample 2 · Sizing the fields of an instruction (Mano)

A computer has a memory of 256K words of 32 bits. An instruction is stored in one word and has four parts: an indirect bit, an opcode, a register code for one of 64 registers, and an address. How many bits does each part have?

  1. Address: 256K = 218 words, so 18 bits.
  2. Register code: 64 = 26 registers, so 6 bits.
  3. Indirect bit: 1 bit.
  4. Opcode: 32 - 18 - 6 - 1 = 7 bits (up to 128 operations).
AnswerI = 1, opcode = 7, register = 6, address = 18 bits

3. Computer Registers

SymbolBitsNameFunction
DR16data registerholds the memory operand
AR12address registerholds the address for memory
AC16accumulatorprocessor register for results
IR16instruction registerholds the instruction code
PC12program counterholds the address of the next instruction
TR16temporary registerholds temporary data
INPR8input registerholds the input character
OUTR8output registerholds the output character

There are also 1-bit flip-flops: E (the carry/extension bit of AC), I (the addressing-mode bit copied from IR), S (start/stop), R (interrupt), IEN (interrupt enable), and FGI, FGO (input and output flags).

The PC goes through the instructions in sequence: after each fetch it is incremented, and a branch instruction loads it with a new address. AR and PC are 12 bits because they hold addresses.

4. The Common Bus System

Connecting every register to every other with separate wires would need a huge number of paths. Instead all registers share one 16-bit common bus. At any moment one source drives the bus, selected by three lines S2 S1 S0 (the bus is really eight 16-input multiplexers' worth: one 8-to-1 multiplexer per bit).

Registers connected to the common busRegisters connected to the common bus

S2 S1 S0Register on the bus
000none
001AR
010PC
011DR
100AC
101IR
110TR
111Memory (word at address AR)

The destination is whichever register has its LD (load) input enabled during the clock transition. Registers also have INR (increment) and CLR (clear) inputs. Memory is written from the bus when its Write input is active, and read onto the bus (select 111) with Read; the memory address always comes from AR.

Details to remember:

  • AR and PC are 12 bits: when they load from the bus, the 4 high bits are ignored; when they drive the bus, the 4 high bits are 0.
  • AC is not loaded from the bus: its input comes from the adder and logic circuit, which takes AC, DR and INPR.
  • INPR feeds only the adder and logic circuit; OUTR receives from the bus only.
  • Two transfers can happen in the same clock if they use different paths: for example DR ← AC (through the bus) and AC ← DR (through the adder and logic circuit).
SolvedExample 3 · Bus selection and control inputs

For each transfer, give S2 S1 S0 and the control inputs that must be active: (a) AR ← PC; (b) IR ← M[AR]; (c) M[AR] ← TR; (d) AC ← DR and DR ← AC together.

  1. (a) PC onto the bus: S = 010; load AR: LD(AR).
  2. (b) Memory onto the bus: S = 111, Read; load IR: LD(IR).
  3. (c) TR onto the bus: S = 110; Write memory.
  4. (d) AC onto the bus: S = 100, LD(DR); at the same time the adder and logic circuit passes DR to AC: LD(AC) with the "transfer DR" function.
Answer(a) 010, LD(AR); (b) 111, Read, LD(IR); (c) 110, Write; (d) 100, LD(DR), LD(AC)
SolvedExample 4 · Why multiplexers?

The bus carries 16 bits from 8 possible sources. How large are the multiplexers that form it?

  1. Each bit of the bus selects one of 8 sources: one 8-to-1 multiplexer per bit, controlled by S2 S1 S0.
  2. 16 bits: 16 multiplexers, each 8 × 1.
Answersixteen 8 × 1 multiplexers sharing the same select lines

5. The Common Bus in Verilog

A bus is a multiplexer: a chain of conditional expressions chooses the source from sel. Each register loads from the bus on the clock edge if its LD signal is set. The testbench performs the first two steps of an instruction fetch and then a memory write:

VERILOG
// The common bus of the basic computer: S2S1S0 chooses which register drives the bus,
// and a register's LD input copies the bus into it on the clock edge.
module bus_system (
    input         clk,
    input  [2:0]  sel,                  // 1 AR, 2 PC, 3 DR, 4 AC, 5 IR, 6 TR, 7 memory
    input         ld_ar, ld_pc, ld_dr, ld_ir, ld_tr, inr_pc, write,
    output [15:0] bus
);
    reg [11:0] AR, PC;
    reg [15:0] DR, AC, IR, TR;
    reg [15:0] M [0:4095];

    assign bus = (sel == 3'd1) ? {4'b0, AR} :
                 (sel == 3'd2) ? {4'b0, PC} :
                 (sel == 3'd3) ? DR :
                 (sel == 3'd4) ? AC :
                 (sel == 3'd5) ? IR :
                 (sel == 3'd6) ? TR :
                 (sel == 3'd7) ? M[AR] : 16'h0000;

    always @(posedge clk) begin
        if (ld_ar) AR <= bus[11:0];
        if (ld_pc) PC <= bus[11:0];
        if (ld_dr) DR <= bus;
        if (ld_ir) IR <= bus;
        if (ld_tr) TR <= bus;
        if (inr_pc) PC <= PC + 1'b1;
        if (write) M[AR] <= bus;
    end
endmodule

module tb;
    reg clk = 0;
    reg [2:0] sel = 0;
    reg ld_ar = 0, ld_pc = 0, ld_dr = 0, ld_ir = 0, ld_tr = 0, inr_pc = 0, write = 0;
    wire [15:0] bus;

    bus_system cpu (.clk(clk), .sel(sel), .ld_ar(ld_ar), .ld_pc(ld_pc), .ld_dr(ld_dr),
                    .ld_ir(ld_ir), .ld_tr(ld_tr), .inr_pc(inr_pc), .write(write), .bus(bus));

    task pulse;
        begin
            #5 clk = 1;
            #5 clk = 0;
            {ld_ar, ld_pc, ld_dr, ld_ir, ld_tr, inr_pc, write} = 7'b0;
        end
    endtask

    initial begin
        cpu.PC = 12'h020;
        cpu.M[12'h020] = 16'h2105;          // an instruction word
        cpu.TR = 16'hBEEF;

        sel = 3'd2; ld_ar = 1;               // AR <- PC
        #1 $display("S=%b  AR <- PC             bus=%h", sel, bus);
        pulse;
        sel = 3'd7; ld_ir = 1; inr_pc = 1;   // IR <- M[AR], PC <- PC + 1
        #1 $display("S=%b  IR <- M[AR], PC+1    bus=%h", sel, bus);
        pulse;
        sel = 3'd6; write = 1;               // M[AR] <- TR
        #1 $display("S=%b  M[AR] <- TR          bus=%h", sel, bus);
        pulse;
        $display("AR=%h PC=%h IR=%h M[020]=%h", cpu.AR, cpu.PC, cpu.IR, cpu.M[12'h020]);
    end
endmodule

After the fetch, IR holds the instruction from address 020 and PC has advanced to 021; the last transfer then overwrites that memory word with TR:

OUTPUT
S=010  AR <- PC             bus=0020
S=111  IR <- M[AR], PC+1    bus=2105
S=110  M[AR] <- TR          bus=beef
AR=020 PC=021 IR=2105 M[020]=beef
💡 Tip

Key points to remember

  • Stored program: instructions and data in the same memory; instruction = opcode + address.
  • Basic computer: 4096 × 16 memory, instruction = I (1) + opcode (3) + address (12).
  • I = 0 direct (EA = address), I = 1 indirect (EA = M[address]).
  • Registers: DR, AR, AC, IR, PC, TR (16 or 12 bits), INPR, OUTR (8 bits); flip-flop E.
  • Bus select: 1 AR, 2 PC, 3 DR, 4 AC, 5 IR, 6 TR, 7 memory. AC loads from the adder, not the bus.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. Explain the stored program organisation. Draw the instruction format of the basic computer and explain direct and indirect addressing. (5 Marks)
  • Q2. List the registers of the basic computer with their sizes and functions. (5 Marks)
  • Q3. Draw the common bus system of the basic computer and explain how S2S1S0 and the LD inputs control transfers. (10 Marks)
  • Write: the 16-bit bus, the select table, the destination LD inputs, memory read/write with AR as address, the adder and logic path into AC.
  • Q4. A memory has 256K words of 32 bits. Find the size of each field of an instruction with I, opcode, register (64 registers) and address parts. (5 Marks)
  • Q5. Give the bus select code and control inputs for IR ← M[AR] and M[AR] ← TR. (2.5 Marks)