Instruction Codes, Computer Registers, and the Common Bus System
Overview: For an instruction that loads a value, the program counter identifies the instruction to fetch.
Introduction: The Stored Program Concept
- All modern computers follow the Stored Program Organization designed by mathematician John von Neumann.
- In this model, both your program code (instructions) and your data (variables, numbers) live together in the same RAM memory.
- The CPU fetches instructions one by one and executes them in sequence.
Instruction Codes and Addressing Bits
- An Instruction Code is a group of binary bits that tells the CPU what math or logic operation to perform, and where to find the data.
- Bit 15 (I) Addressing Mode Bit 0 = Direct , 1 = Indirect
- Bits 12–14 (Opcode) Operation Code (3 bits) Tells what action to do (ADD, SUB, AND)
- Bits 0–11 (Address) Memory Address (12 bits) Points to one of 4,096 memory words
- Direct vs. Indirect Addressing: Direct Addressing (I = 0): The 12-bit address points directly to the data operand in memory.
- Indirect Addressing (I = 1): The address points to a memory location that contains another address where the real data is stored!
- An everyday example
-
- Direct Addressing (
I = 0): Your friend gives you the exact room number where your lecture is held.
- Direct Addressing (
View diagram · 16-Bit Instruction Format
Basic Computer Registers
- To fetch and execute instructions, the CPU needs special internal storage boxes called Registers:
- DR: 16 bits
- AR: 12 bits
- AC: 16 bits
- IR: 16 bits
- PC: 12 bits
- TR: 16 bits
The Common Bus System
- If you connected individual wires between every register, the CPU would be a tangled mess of copper!
- Instead, all registers share one common 16-line highway called the Common Bus.
- At any given moment, only one register is allowed to place its data on the bus.
- Three select lines (S₂, S₁, S₀) control the multiplexers to choose which register uses the bus:
- Bus Selection Codes:
001: AR places address on the bus. 010: PC places next address on the bus.011: DR places data on the bus.100: AC places accumulator value on the bus.
Instruction Cycle, Timing and Control, and Memory-Reference Instructions
Overview: After fetching an instruction the processor normally advances the program counter.
What is the Instruction Cycle?
- Whenever you click Run on a C, C++, or Java program, the CPU processes your code line by line.
- The CPU runs a continuous loop called the Instruction Cycle.
- Every single instruction goes through 4 essential phases:
- Fetch: Bring the instruction from RAM memory into the CPU.
- Decode: Find out what the instruction wants to do.
- Read Effective Address: If indirect addressing is used, fetch the real operand pointer.
- Execute: Perform the actual calculation or action.
- An everyday example
Timing and Control Unit
- Inside the CPU, timing is controlled by a master clock and a Sequence Counter (SC):
- The Sequence Counter counts from 0 to 15.
- A 4-to-16 Line Decoder splits this count into 16 separate timing signals: T₀, T₁, T₂, …, T₁₅.
- Each timing step stays active for exactly one clock tick.
- Once an instruction finishes executing, the control unit resets the counter (
SC ← 0) to begin the next instruction atT₀.
Step-by-Step Instruction Cycle Micro-operations
- Fetch brings in the instruction and decode identifies the requested operation.
- T0: Address Fetch Address from Program Counter moves to Address Register: AR ← PC
- T1: Memory Read Instruction copied to IR and PC advances: IR ← M[AR], PC ← PC + 1
- T2: Decode Phase Opcode decoded (D₀-D₇), address moved to AR, mode bit I loaded
- T3: Effective Address If I = 1 (Indirect), load pointer: AR ← M[AR]; if I = 0, do nothing
- Detailed Micro-operations: At T₀:
AR ← PC - At T₁:
IR ← M[AR],PC ← PC + 1 - At T₂: Decode Opcode bits 12-14 into
D₀throughD₇, copy address bits 0-11 toAR, and load mode bit 15 into flip-flopI.
View diagram · The Four Phases of Instruction Cycle
Seven Memory-Reference Instructions
- When the opcode decoder produces
D₀toD₆, the instruction accesses RAM memory: - 1. AND (D₀): Logical AND with Accumulator: RTL:
- Performs bitwise AND between Accumulator (
AC) and data from memory. - 2. ADD (D₁): Binary Addition: RTL:
- Adds memory data to
AC, storing the carry-out bit in flip-flopE. - 3. LDA (D₂): Load Accumulator: RTL:
- Copies data from memory into
AC. - 4. STA (D₃): Store Accumulator: RTL:
Input-Output Organization, Interrupts, and Assembly Language
Overview: A keyboard produces data at irregular times.
What is I/O Organization?
- A computer is useless if it cannot talk to us.
- The Huge Speed Problem: The CPU runs at lightning speeds—executing billions of instructions every second.
- Humans type very slowly—maybe 2 to 4 keystrokes per second.
- If the CPU sat idle waiting for your finger to press a key, 99.9% of its processing power would be completely wasted!
Input-Output Configuration and Flags
- The computer talks to input/output devices using two 8-bit registers and two 1-bit status flags:
- Input Device (Keyboard) Sends 8-bit ASCII character to INPR .
- Output Device (Monitor) Displays 8-bit ASCII from OUTR .
- How the Handshaking Flags Work: FGI (Input Flag):
- FGO (Output Flag):
View diagram · Input-Output Handshaking Architecture
Input-Output Instructions
- All I/O instructions have the opcode
111(D₇ = 1) with mode bitI = 1: - INP:
F800 - OUT:
F400 - SKI:
F200 - SKO:
F100 - ION:
F080 - IOF:
F040
The Program Interrupt Cycle
- Why Do We Need Interrupts? (Polling vs. Interrupts): Polling (Programmed I/O): The CPU continuously loops checking: *“Did you press a key?
- Interrupts: The CPU does useful work (e.g., playing music, calculating spreadsheets).
- An everyday example
-
- Polling: Standing at your hostel gate for 2 hours waiting for your Swiggy delivery.
-
- Interrupt: You study peacefully in your room.
- 3 Hardware Steps of the Interrupt Cycle: When an interrupt arrives (
IEN = 1andFGI = 1orFGO = 1): - Step 1 (T₀’): CPU prepares memory location
0and stores the current return address: - Step 2 (T₁’): Saves the return address into RAM memory location 0, and resets PC:
Machine Language vs. Assembly Language
- Format: Raw binary bits (
0001 0000 0010 0100) or hex - Execution: Runs directly on silicon chips
- Readability: Almost impossible for humans to read
- Portability: Locked to that specific CPU model
Addressing Modes, Instruction Formats, and Formal Instruction Design
Overview: If register R contains 20 and memory location 20 contains 75, register addressing reads 20.
What is an Addressing Mode?
- When the CPU executes an instruction like
ADD, it needs to know: Where is the number to be added? - Is the number written directly inside the instruction?
- Is it sitting inside a fast CPU register like
R₁? - Is it saved in RAM memory?
- Is it an item inside a large C-language array?
Primary Addressing Modes
- Immediate addressing carries the operand inside the instruction.
- Immediate Mode Operand = Value inside instruction Data is right there (e.g.
- Direct Mode EA = Address Instruction gives the exact RAM address (e.g.
- Indirect Mode EA = M[Address] Instruction points to a memory pointer that holds the real address
- Register Mode Operand = Register Data is stored inside a fast CPU register (R₁)
- 1. Implied (Implicit) Mode: No address is needed!
- Example:
CMA(Complement Accumulator) orCLC(Clear Carry). - 2. Immediate Mode: The actual number is written right inside the instruction.
View diagram · Common Addressing Modes and Effective Address (EA)
Indian Heritage: Pāṇini’s Formal Rules and Computer Instruction Sets
- In the DAVV BCA syllabus, students study how ancient Indian grammar parallels modern computer architecture:
- 💡 Cultural & Technical Connection:
- Around 2,500 years ago in ancient India, the scholar Pāṇini composed the Aṣṭādhyāyī.
- It contained 3,959 formal rules (sūtras) that systematically generated every correct word in Sanskrit.
- World-renowned computer scientists (like Donald Knuth) consider Pāṇini’s work to be the **world’s first formal rule-based grammar…
- Direct Parallels to Computer Instructions:
-
-
Register Transfer Language (RTL) and Bus / Memory Transfer
Overview: The notation R2 receives R1 means R2 gets a copy.
What is Register Transfer Language?
- Inside a computer CPU, data constantly moves between internal registers.
- Drawing thousands of gates and wires to explain this is impossible.
- Instead, computer engineers use a simple shorthand notation called Register Transfer Language (RTL).
- The elementary operations performed on data inside registers during a single clock pulse are called Micro-operations.
- An everyday example
- Think of shorthand text messaging.
- Instead of writing “Please transfer fifty rupees to my account”, you write a quick UPI code!
- RTL is the shorthand code that describes hardware data movements clearly.
RTL Notation and Conditional Transfer
- The replacement of data from one register into another is written with an arrow operator (←):
- Conditional Transfer: In computer hardware, data must only move when a specific control signal is ON:
- P is a control signal generated by the CPU control unit.
- If P = 1, the transfer happens on the next clock pulse.
- If P = 0, nothing happens; registers keep their old data.
View diagram · Conditional Transfer Hardware Implementation
Bus Transfer Using Multiplexers
- Why do we need a common Bus?
- If a CPU has 8 registers and you connect separate wires between every single pair, you would need hundreds of messy wires!
- Instead, a Common Bus acts like a shared single highway.
- Connecting 4 Registers to a Bus Using Multiplexers: To connect four 4-bit registers (
A,B,C,D) to a 4-line bus, we use four 4-to-1 Multiplexers: - Each MUX handles 1 bit position across all 4 registers.
- Two Select Lines (S₁, S₀) decide which register gets control of the bus:
- 0: 0
- 0: 1
Bus Transfer Using Three-State Bus Buffers
- A cleaner, modern way to build a common bus is using Three-State (Tri-State) Buffers.
- Logic 0 Normal low-voltage output (0V)
- Logic 1 Normal high-voltage output (+5V)
- 0: 1
- 1: 1
- X (Any): 0
- Why is Hi-Z so Useful?: In normal circuits, connecting multiple outputs to the same copper wire causes a short circuit!
- Only one buffer has
Enable = 1and drives data onto the bus.
View diagram · Three-State Buffer States
Memory Transfers: Read and Write Operations
- The CPU treats RAM memory as a huge collection of storage cells denoted by M:
- 1. Memory Read Operation: Read the data from the memory location stored in the Address Register (AR) into the Data Register (DR):
- 2. Memory Write Operation: Write the contents of register R₁ into the memory address specified by AR:
Arithmetic, Logic, and Shift Micro-operations (ALU Design)
Overview: Starting from 0101, adding one gives 0110.
What are Micro-operations?
- No matter how complex a computer program or game is, the CPU breaks every instruction down into tiny, atomic hardware steps called…
- A Micro-operation is an elementary operation performed on data stored inside registers during a single clock cycle.
- The Arithmetic Logic Unit (ALU) executes these micro-operations.
- 1. Register Transfer Copies binary data from one register to another (
R₂ ← R₁) - 4. Shift Slides data bits left or right for quick multiplication or division
View diagram · The Four Classes of Micro-operations
Arithmetic Micro-operations
- The basic math operations include:
- Add:
R₃ ← R₁ + R₂ - Subtract (via 2’s complement):
R₃ ← R₁ + R₂' + 1 - Increment (Add 1):
R₁ ← R₁ + 1 - Decrement (Minus 1):
R₁ ← R₁ - 1 - The 4-Bit Arithmetic Circuit: Built using 4 Full Adders and 4 Multiplexers.
- 0: 0
- 0: 0
Logic Micro-operations and Bit Manipulation
- Logic micro-operations treat each bit in a register independently (no carry is passed between columns).
- An everyday example
- Think of marking attendance on a register page.
- You mark each student’s checkbox one-by-one without affecting other rows.
- Bit-manipulation does the exact same thing to individual bits!
- Four Essential Bit-Manipulation Tricks: Selective Set (Uses OR): Turns chosen target bits into
1without changing the other bits. - Example:
1010OR0100=1110(Bit 2 is forced ON). - Selective Clear (Uses AND with Inverted Mask): Forces chosen target bits to
0.
Shift Micro-operations
- A logical shift fills a vacant position with zero.
- Logical Shift Slides all bits.
- Circular Shift (Rotate) The bit pushed out of one end loops right back into the opposite end.
- Detecting Overflow in Arithmetic Shift Left: When you shift a signed number left, you double its value.
- If the number becomes too large for the register, the sign bit flips incorrectly!
- The CPU detects this Overflow using an XOR gate on the two leftmost bits:
- If V = 1, an overflow error flag is set.