π Lecture 4 β ISA and Instruction Formats
π Overview: This lecture introduces the Instruction Set Architecture (ISA) and instruction formats using the SRC (Simple RISC Computer) as an example machine. It covers SRC attributes, instruction types, addressing modes, and hand assembly, providing a foundation for understanding computer architecture design.
ποΈ Topics Covered
The lecture covers the SRC's attributes including registers, memory organization, and notation. It details four instruction formats (Types A through D) with their op-codes, operands, and addressing modes. The lecture includes coding examples for expression evaluation and extensive hand assembly demonstrations converting assembly language to machine code, along with assembler directives and memory mapping.
π Lecture Summary
Introduction to ISA and instruction formats
The lecture introduces the Instruction Set Architecture (ISA) as the interface between hardware and software, using the SRC (Simple RISC Computer) as an example machine. This example machine is simple enough to illustrate fundamentals while leaving out many details of a real computer.
An example computer: the SRC: βsimple RISC computerβ
SRC Introduction
The SRC is introduced as an example machine to facilitate understanding of various design steps and concepts in computer architecture. Though quite simple, it is complex enough to illustrate the fundamentals.
Attributes of the SRC
The SRC contains 32 General Purpose Registers: R0, R1... R31, each of size 32-bits. Two special purpose registers are included: Program Counter (PC) and Instruction Register (IR). Memory word size is 32 bits, memory space size is 2Β³Β² bytes, and memory organization is 2Β³Β² x 8 bits, meaning memory is byte aligned. Memory is accessed in 32 bit words (4 byte chunks), and Big-endian byte storage is used.
Programmerβs View of the SRC
The programmer sees 32, 32-bit registers as part of the CPU, the two additional CPU registers (PC & IR), and the main memory which is 2Β³Β² 1-byte cells.
SRC Notation
Key notation examples: R[3] means contents of register 3, M[8] means contents of memory location 8. A memory word at address 8 is defined as the 32 bits at addresses 8,9,10 and 11 in memory. A special notation for 32-bit memory words is M[8]<31...0>:=M[8] M[9] M[10] M[11] used for concatenation.
Some more SRC Attributes
All instructions are 32 bits long (instruction size is 1 word). All ALU instructions have three operands. The only way to access memory is through load and store operations. Only a few addressing modes are supported.
SRC: Instruction Formats
Four types of instructions (Type A, B, C, D) are supported by the SRC.
π Definition β Encoding of General Purpose Registers: A simple 5-bit encoding where ra, rb, and rc are field "place-holders" that can represent any of the 32 registers. An exception is rb = 0; it does not mean register R0, rather it means no operand.
Type A
Type A is used for only two instructions: nop (No operation, op-code = 0, useful in pipelining) and stop (Stop operation, op-code = 31). Both are 0-operand instructions.
Type B
Type B format includes three instructions, all using relative addressing mode:
- ldr (load register from memory using relative address, op-code = 2): Example
ldr R3, 56loads register R3 with contents of memory location M[PC+56] - lar (load register with relative address, op-code = 6): Example
lar R3, 56loads register R3 with the relative address itself (PC+56) - str (store register to memory using relative address, op-code = 4): Example
str R8, 34stores register R8 contents to M[PC+34]
The effective address is computed at run-time by adding a constant to the PC, making instructions re-locatable.
Type C
Type C format has three load/store instructions plus three ALU instructions.
Load/Store instructions:
- ld (load register from memory, op-code = 1): Example
ld R3, 56loads R3 with M[56] (direct addressing, rb=0). Exampleld R3, 56(R5)loads R3 with M[56+R[5]] (indexed addressing, rbβ 0) - la (load register with immediate value or address, op-code = 5): Example
la R3, 56loads R3 with immediate value 56 (immediate addressing). Examplela R3, 56(R5)loads R3 with indexed address 56+R[5] (indexed addressing) - st (store register contents to memory, op-code = 3): Example
st R8, 34stores R[8] to M[34] (direct addressing). Examplest R8, 34(R6)stores R[8] to M[34+R[6]] (indexed addressing)
ALU instructions:
- addi (immediate 2's complement addition, op-code = 13): Example
addi R3, R4, 56performs R[3] β R[4]+56 - andi (immediate logical AND, op-code = 21): Example
andi R3, R4, 56loads R3 with logical AND of R[4] and 56 - ori (immediate logical OR, op-code = 23): Example
ori R3, R4, 56loads R3 with logical OR of R[4] and 56
π‘ Why this matters: Since the constant c2 field is 17 bits, for direct addressing mode only the first 2ΒΉβΆ bytes of memory can be accessed (or last 2ΒΉβΆ if c2 is negative). For la instruction, only constants with magnitudes less than Β±2ΒΉβΆ can be loaded. During address calculation using c2, sign extension to 32 bits must be performed before addition.
Shift instructions (modified Type C):
- shr (shift right, op-code = 26): Example
shr R3, R4, 7shifts R4 right 7 times into R3, shifting zeros in from left - shra (arithmetic shift right, op-code = 27): Example
shra R3, R4, 7shifts R4 right 7 times into R3, copying msb into word on left - shl (shift left, op-code = 28): Example
shl R8, R5, 6shifts R5 left 6 times into R8, shifting zeros in from right - shc (shift left circular, op-code = 29): Example
shc R3, R4, 3shifts R4 circular 3 times into R3, value shifted out left placed back on right
Type D
Type D includes four ALU instructions, four register-based shift instructions, two logical instructions, and two branch instructions.
ALU instructions (register addressing):
- add (2's complement register addition, op-code = 12): Example
add R3, R5, R6stores R[5]+R[6] in R3 - sub (2's complement register subtraction, op-code = 14): Example
sub R3, R5, R6stores R[5]-R[6] in R3 - and (logical AND between registers, op-code = 20): Example
and R8, R3, R4stores logical AND of R3 and R4 in R8 - or (logical OR between registers, op-code = 22): Example
or R8, R3, R4loads R8 with logical OR of R3 and R4
Register-based shift instructions (register addressing):
- shr (shift right using register rc, op-code = 26): Example
shr R3, R4, R5shifts R4 right into R3 using number in R5 - shra (arithmetic shift right using register rc, op-code = 27): Example
shra R3, R4, R5shifts R4 right using R5 - shl (shift left using register rc, op-code = 28): Example
shl R8, R5, R6shifts R5 left into R8 using number in R6 - shc (shift left circular using register rc, op-code = 29): Example
shc R3, R4, R6shifts R4 circular into R3 using value in R6
Logical instructions (modified Type D, 2-address format):
- neg (2's complement negation, op-code = 15): Example
neg R3, R4negates R4 and stores in R3 - not (1's complement, op-code = 24): Example
not R3, R4logically inverts R4 and stores in R3
Branch instructions (modified Type D, register addressing):
-
br (branch to address in rb depending on condition in rc, op-code = 8): Branches based on five conditions:
brzr R3, R4β Branch to address in R3 if R4 == 0brnz R3, R4β Branch to address in R3 if R4 β 0brpl R3, R4β Branch to address in R3 if R4 β₯ 0brmi R3, R4β Branch to address in R3 if R4 < 0br R3, R4β Unconditional branch to address in R3
-
brl (branch to address in rb depending on condition in rc, copies PC to ra before branching, op-code = 9):
brlzr R1, R3, R4β R1 stores PC, then branch to R3 if R4 == 0brlnz R1, R3, R4β R1 stores PC, then branch to R3 if R4 β 0brlpl R1, R3, R4β R1 stores PC, then branch to R3 if R4 β₯ 0brlmi R1, R3, R4β R1 stores PC, then branch to R3 if R4 < 0brl R1, R3, R4β R1 stores PC, then ALWAYS branch to R3brlnv R1, R3, R4β R1 stores PC, but branch NEVER taken
The bits <2...0> are used for specifying the condition, with condition codes serving as op code extensions.
Examples
Example 1: Expression Evaluation Write an SRC assembly program to evaluate: z = 4(a+b) β 16(c+58), without changing source operands.
Solution A (using shift for multiply since SRC has no multiply instruction):
ld R1, c ; c is a label used for a memory location
addi R3, R1, 58 ; R3 contains (c+58)
shl R7, R3, 4 ; R7 contains 16(c+58)
ld R4, a
ld R5, b
add R6, R4, R5 ; R6 contains (a+b)
shl R8, R6, 2 ; R8 contains 4(a+b)
sub R9, R8, R7 ; the result is in R9
st R9, z ; store the result in memory location z
Memory labels a, b, c, z are defined using assembler directives like .dw or .db. A semicolon ';' is used for comments.
Example 2: Hand Assembly Convert the SRC assembly program to machine language.
Source program with directives:
.ORG 200 ; start the next line at address 200
a: .DW 1 ; reserve one word for label a at address 200
b: .DW 1 ; reserve a word for b at address 204
c: .DW 1 ; reserve a word for c at address 208
z: .DW 1 ; reserve one word for result at address 212
.ORG 400 ; start the code at address 400
ld R1, c ; c is a label used for a memory location
addi R3, R1, 58 ; R3 contains (c+58)
shl R7, R3, 4 ; R7 contains 16(c+58)
ld R4, a
ld R5, b
add R6, R4, R5 ; R6 contains (a+b)
shl R8, R6, 2 ; R8 contains 4(a+b)
sub R9, R8, R7 ; the result is in R9
st R9, z ; store the result in memory location z
Hand Assembly Process for ld R1, c (Type C, rb missing):
- Op-code for ld = 00001
- Register code for R1 = 00001
- rb field missing, place zeros: 00000
- c is at address 208, 17-bit binary = 00000 0000 1101 0000
- Complete instruction: 00001 00001 00000 00000 0000 1101 0000
- Hexadecimal: 0 8 4 0 0 0 D 0 h
For addi R3, R1, 58 (Type C):
- Op-code for addi = 01101
- Register codes: R3 = 00011, R1 = 00001
- Immediate data 58 in binary: 00000 0000 0011 1010
- Complete: 01101 00011 00001 00000 0000 0011 1010
- Hexadecimal: 6 8 C 2 0 0 3 A h
For shl R7, R3, 4 (Type C):
- Op-code for shl = 11100
- Register codes: R7 = 00111, R3 = 00011
- Immediate data 4 in binary: 00000 0000 0000 0100
- Complete: 11100 00111 00011 00000 0000 0000 0100
- Hexadecimal: E1C60004
For ld R4, a (Type C, rb missing):
- Op-code for ld = 00001
- Register code for R4 = 00100
- rb field missing: 00000
- a at address 200, 17-bit binary: 00000 0000 1100 1000
- Complete: 00001 00100 00000 00000 0000 1100 1000
- Hexadecimal: 0 9 0 0 0 0 C 8 h
For ld R5, b (Type C, rb missing):
- Op-code = 00001, R5 = 00101
- rb field missing: 00000
- b at address 204, 17-bit binary: 00000 0000 1100 1100
- Complete: 00001 00101 00000 00000 0000 1100 1100
- Hexadecimal: 0 9 4 0 0 0 C C h
For add R6, R4, R5 (Type D, constant missing):
- Op-code for add = 01100
- Register codes: R6 = 00110, R4 = 00100, R5 = 00101
- 12-bit constant unused: 0000 0000 0000
- Complete: 01100 00110 00100 00101 0000 0000 0000
- Hexadecimal: 6 1 8 8 5 0 0 0 h
For shl R8, R6, 2 (Type C, rc missing):
- Op-code for shl = 11100
- Register codes: R8 = 01000, R6 = 00110
- Immediate data 2 in binary: 00000 0000 0000 0010
- Complete: 11100 01000 00110 00000 0000 0000 0010
- Hexadecimal: E 2 0 C 0 0 0 2
For sub R9, R7, R8 (Type D):
- Op-code for sub = 01110
- Register codes: R9 = 01001, R7 = 00111, R8 = 01000
- 12-bit constant unused: 0000 0000 0000
- Complete: 01110 01001 00111 01000 0000 0000 0000
- Hexadecimal: 7 2 4 E 8 0 0 0 h
For st R9, z (Type C, rb missing):
- Op-code for st = 00011
- Register code for R9 = 01001
- rb field missing: 00000
- z at address 212, 17-bit binary: 00000 0000 1101 0100
- Complete: 00011 01001 00000 00000 0000 1101 0100
- Hexadecimal: 1 A 4 0 0 0 D 4 h
Memory Map (byte-aligned representation):
| Address | Contents |
|---|---|
| 200-203 | a (1 word) |
| 204-207 | b (1 word) |
| 208-211 | c (1 word) |
| 212-215 | z (1 word) |
| 400-403 | 0x084000D0 (ld R1, c) |
| 404-407 | 0x68C2003A (addi R3, R1, 58) |
| 408-411 | 0xE1C60004 (shl R7, R3, 4) |
| 412-415 | 0x090000C8 (ld R4, a) |
| 416-419 | 0x094000CC (ld R5, b) |
| 420-423 | 0x61885000 (add R6, R4, R5) |
| 424-427 | 0xE20C0002 (shl R8, R6, 2) |
| 428-431 | 0x724E8000 (sub R9, R8, R7) |
| 432-435 | 0x1A4000D4 (st R9, z) |
Assembler Directives
Assembler directives (pseudo op-codes) are commands to the assembler to direct the assembly process. Key directives used:
- .ORG β Specifies starting address for code/variables (e.g.,
.ORG 200) - .DW β Reserves one word in memory for a label (e.g.,
a: .DW 1) - Most assemblers require source files saved with .asm extension
β Key Takeaways
Students must understand the four SRC instruction formats (Types A, B, C, D) and their op-codes, addressing modes, and operand structures. The 5-bit register encoding (R0-R31) and the special meaning of rb=0 (no operand) are critical. Hand assembly requires careful mapping of op-codes, register codes, and immediate/address values into the correct bit fields, with sign extension for negative constants. Memory organization uses byte alignment with 32-bit words and big-endian storage. The relationship between assembly instructions, machine code (binary and hexadecimal), and memory addresses must be mastered for understanding computer architecture fundamentals.
π§ Quick Revision Questions
- What are the four instruction types in the SRC, and what is each used for?
- How many general purpose registers does the SRC have, and what is the bit width of each?
- What is the difference between the
ldandldrinstructions in terms of addressing mode? - How would you encode the instruction
add R5, R2, R3into machine language (binary and hexadecimal)? - What is the purpose of the
.ORGand.DWassembler directives?
π Lecture 5 β Description of SRC in RTL
π Overview: This lecture introduces how to describe the SRC (Simple 'RISC' Computer) using Register Transfer Language (RTL). It covers both behavioral and structural descriptions, explains how to specify registers and fields, and details the instruction interpretation and execution phases of the fetch-execute cycle.
ποΈ Topics Covered
The lecture covers reverse assembly of machine language instructions into SRC assembly, the definition and use of RTL for behavioral and structural descriptions, specification of static properties including registers and instruction fields, dynamic properties including effective address calculations, and detailed description of instruction interpretation (fetch) and execution phases for all instruction types including load-store, branch, arithmetic/logical, shift, and miscellaneous instructions.
π Lecture Summary
Reverse Assembly
Reverse assembly is the process of converting machine language instructions back into their equivalent SRC assembly language instructions. The process involves writing the hexadecimal instruction in binary, examining the first five bits to determine the op-code and corresponding mnemonic, and then interpreting the remaining fields based on the instruction format.
π Definition β Reverse Assembly: The process of finding the equivalent SRC assembly language instruction from a given machine language instruction.
π Example: Reverse assemble 68C2003A h
- Step 1: Convert to binary: 0110 1000 1100 0010 0000 0000 0011 1010 b
- Step 2: First 5 bits = 01101 b = 13 d β addi (add immediate)
- Step 3: This uses Type C format: op-code (01101), ra field (00011=R3), rb field (00001=R1), 17-bit c1 field (00000 0000 0011 1010 = 3A h = 58 d)
- Result: addi R3, R1, 58
π Example: E1C60004 h β 1110 0001 1100 0110 0000 0000 0000 0100 b β op=11100=28 d β shl (shift left) β Type C format β shl R3, R1, 4
π Example: 61885000 h β 0110 0001 1000 1000 0101 0000 0000 0000 b β op=01100=12 d β add β Type C format β add R3, R1, R0
π Example: 724E8000 h β 0111 0010 0100 1110 1000 0000 0000 0000 b β op=01110=14 d β sub β sub R1, R2, R3
π Example: 1A4000D4 h β 0001 1010 0100 0000 0000 0000 1101 0100 b β op=00011=3 d β st (store) β Type C β st R1, R0, D4h
π Example: 084000D0 h β 0000 1000 0100 0000 0000 0000 1101 0000 b β op=00001=1 d β ld (load) β ld R1, R0, D0h
π‘ Why this matters: Reverse assembly is essential for debugging and understanding machine code output from assemblers.
Using RTL to Describe the SRC
RTL stands for Register Transfer Language, which provides a formal way for describing the behavior and structure of a computer. RTL facilitates the design process by providing a precise, mathematical representation of functionality.
Behavioral RTL describes the 'functionality' of the machine only β what the machine does. Structural RTL describes the 'hardware implementation' of the machine β how the functionality is implemented. In computer design, a top-down approach is adopted: starting with behavioral description, then breaking down into modules, until we can define, design, and implement the structure of individual modules.
Using RTL to Describe Static Properties of the SRC
Specifying Registers: The format used is Register Name<register bits>. For example, IR<31..0> means bits 31 to 0 of a 32-bit register named "IR" (Instruction Register).
The := operator is the naming operator used to 'name' registers or parts of registers. It does not create a new register; it just generates another name or "alias" for an already existing register or part of a register.
π Definition β Naming Operator (:=): Creates an alias for an existing register or part of a register. For example, Op<4..0> := IR<31..27> means the five most significant bits of IR will be called op.
Fields in the SRC Instruction
Using RTL, the various fields of an SRC instruction are specified:
op<4..0> := IR<31..27>; operation code field (5 most significant bits)ra<4..0> := IR<26..22>; target register field (where the result is stored)rb<4..0> := IR<21..17>; operand, address index, or branch target registerrc<4..0> := IR<16..12>; second operand, conditional test, or shift count registerc1<21..0> := IR<21..0>; long displacement field (22 bits)c2<16..0> := IR<16..0>; short displacement or immediate field (17 bits)c3<11..0> := IR<11..0>; count or modifier field (12 bits)
Note: There is overlap of fields. The fields are distinguished in a particular instruction depending on the operation.
Describing Processor State Using RTL
The following registers and bits together form the processor state set:
PC<31..0>; program counter (holds memory address of next instruction)IR<31..0>; instruction register (holds current instruction)Run; one bit run/halt indicatorStrt; start signalR [0..31]<31..0>; 32, 32-bit general purpose registers
Difference Between "," and ";" in RTL
Statements separated by a "," take place during the same clock pulse β the order of execution does not matter. Statements separated by a ";" take place on successive clock pulses β the one on the left must complete before the one on the right starts.
In statements separated by ",", all right-hand sides of Register Transfers are evaluated before any left-hand side is modified.
Using RTL to Describe Dynamic Properties of the SRC
Conditional expressions can be specified through RTL:
π Example: (op=14) : R [ra] β R [rb] - R[rc];
The β operator is the RTL assignment operator. ; is the termination operator. This means: "IF the op field equals 14, THEN calculate the difference of the value in register rb and register rc, and store the result in register ra."
Effective Address Calculations in RTL
Displacement address (calculated at runtime):
disp<31..0> := ((rb=0) : c2<16..0> {sign extend}, (rbβ 0) : R [rb] + c2<16..0> {sign extend})
If rb=0, just use the displacement value (sign extended). If rbβ 0, add the register value to the displacement. The comma separates disjoint conditions β only one action will be performed at a time.
Relative address: rel<31..0> := PC<31..0> + c1<21..0> {sign extend}
Range of memory addresses:
- Direct addressing (displacement with rb=0):
- If c2<16>=0 (positive): addresses from 00000000h to 0000FFFFh
- If c2<16>=1 (negative): addresses from FFFF0000h to FFFFFFFFh
- Relative addressing: Largest positive c1 value is 2Β²ΒΉ-1, most negative is -2Β²ΒΉ, so addresses up to 2Β²ΒΉ-1 forward and 2Β²ΒΉ backward from current PC
Instruction Interpretation (Fetch Operation Using RTL)
The action performed for all instructions before they are decoded is called instruction interpretation.
π Formula:
instruction_Fetch := (
!Run & Strt: Run β 1 ; instruction_Fetch
Run : (IR β M [PC], PC β PC + 4; instruction_Execution)
);
If the machine is not running (!Run) AND start (Strt) becomes true, Run is set to 1. If running, the instruction register is loaded with the instruction at M[PC] and PC is incremented by 4 simultaneously.
Instruction Execution (Execute Operation Using RTL)
Once the instruction is fetched and PC incremented, execution starts. iF denotes instruction fetch and iE denotes instruction execution.
π Formula:
iE:= (
(op<4..0>=1) : R [ra] β M [disp],
(op<4..0>=2) : R [ra] β M [rel],
...
(op<4..0>=31) : Run β 0,); iF);
One statement is executed depending on the condition met, then iF is invoked again β forming the fetch-execute cycle.
Load-Store Instructions
- ld (op=1):
R [ra] β M [disp]β Load register using displacement address - ldr (op=2):
R [ra] β M [rel]β Load register using relative address - st (op=3):
M [disp] β R [ra]β Store register to displacement address - str (op=4):
M[rel] β R[ra]β Store register to relative address - la (op=5):
R [ra] β dispβ Load displacement address into register - lar (op=6):
R [ra] β relβ Load relative address into register
Branch Instructions
- br (op=8):
(cond : PC β R [rb])β Conditional branch to target in rb - brl (op=9):
(R [ra] β PC, cond : (PC β R [rb]) )β Branch and link: store PC in ra, then branch
The cond conditions depend on c3<2..0>:
- c3=0: 0 β never branch
- c3=1: 1 β always branch
- c3=2:
R [rc]=0β branch if register zero - c3=3:
R [rc] β 0β branch if register nonzero - c3=4:
R [rc]<31>=0β branch if positive or zero - c3=5:
R [rc]<31>=1β branch if negative
Arithmetic and Logical Instructions
- add (op=12):
R [ra] β R [rb] + R [rc] - addi (op=13):
R [ra] β R [rb] + c2<16..0> {sign extend} - sub (op=14):
R [ra] β R [rb] β R [rc] - neg (op=15):
R [ra] β -R [rc] - and (op=20):
R [ra] β R [rb] & R [rc] - andi (op=21):
R [ra] β R [rb] & c2<16..0> {sign extend} - or (op=22):
R [ra] β R [rb] ~ R [rc] - ori (op=23):
R [ra] β R [rb] ~ c2<16..0> {sign extend} - not (op=24):
R [ra] β Β¬R [rc]
Shift Instructions
- shr (op=26):
R [ra]<31..0> β (n Ξ± 0) Β© R [rb] <31..n>β Shift right n bits, fill with 0s - shra (op=27):
R [ra]<31..0> β (n Ξ± R [rb] <31>) Β© R [rb] <31..n>β Shift right arithmetic (fill with sign bit) - shl (op=28):
R [ra]<31..0> β R [rb] <31-n..0> Β© (n Ξ± 0)β Shift left n bits - shc (op=29):
R [ra]<31..0> β R [rb] <31-n..0> Β© R [rb]<31..32-n>β Shift circular (bits rotate)
Where n := ((c3<4..0>=0) : R [rc], (c3<4..0>!=0) : c3<4..0>)
Notation: Ξ± means replication, Β© means concatenation
Miscellaneous Instructions
- nop (op=0): No operation β used as a stall in pipelining
- stop (op=31):
Run β 0β Halt the processor
Flow Diagram
The flow diagram is the symbolic representation of the fetch-execute cycle. The top block indicates instruction fetch, then instruction decode by looking at the first 5 bits for the op-code (0 to 31). Depending on the op-code, appropriate processing takes place, then the cycle returns to fetch the next instruction until op-code 31 halts the system.
β Key Takeaways
The most critical concepts from this lecture are: (1) RTL uses the := naming operator to create aliases for register fields, the β assignment operator for data transfers, , for concurrent operations within one clock, and ; for sequential operations across clocks; (2) the instruction format consists of op (bits 31-27), ra (26-22), rb (21-17), rc (16-12), and various displacement fields (c1, c2, c3) with overlapping bits distinguished by the operation; (3) the fetch-execute cycle is defined as iF fetching IRβM[PC] and PCβPC+4 concurrently, then iE executing one of 31 disjoint conditional operations based on the op-code; (4) effective address calculations include displacement addressing (disp) and relative addressing (rel) with specific memory address ranges; and (5) branch instructions use six conditional tests specified by the c3 field including never, always, zero, nonzero, positive/zero, and negative.
π§ Quick Revision Questions
- What is the difference between the "," and ";" operators in RTL, and how do they affect execution timing?
- Describe the step-by-step process for reverse assembling the machine instruction 724E8000h into SRC assembly language.
- Write the RTL expressions for the op, ra, rb, and rc fields and identify which bits of the IR register each field occupies.
- Explain how the displacement address (disp) is calculated in RTL and describe the difference when rb=0 versus rbβ 0.
- What are the six possible branch conditions specified by the c3 field, and what does each condition test?
π Lecture 6 β RTL Using Digital Logic Circuits
π Overview: This lecture continues the discussion of behavioral RTL for describing the SRC processor, covering the complete instruction set including load-store, branch, arithmetic/logical, shift, and miscellaneous instructions. It then transitions into the hardware implementation of register transfers using digital logic circuits, reviewing basic components like D flip-flops, registers, multiplexers, and tri-state buffers, and demonstrating how these are used to build buses, register files, and functional units like adders and barrel shifters.
ποΈ Topics Covered
The lecture begins by completing the behavioral RTL description of the SRCβs instruction set, detailing each instruction class (load-store, branch, arithmetic/logical, shift, miscellaneous). The second major section covers implementing register transfers with digital logic, starting with a review of fundamental components (D flip-flops, n-bit registers, n-to-1 multiplexers, tri-state buffers), then building up to simple conditional transfers, two-way transfers, multiple register connections, bus architectures, register file implementation, register transfers with mathematical operations (using adders), and finally the barrel shifter for implementing shift operations.
π Lecture Summary
Using behavioral RTL to Describe the SRC (continued)
Once the instruction is fetched and the PC is incremented, execution of the instruction starts. In the following discussion, we denote instruction fetch by βiFβ and instruction execution by βiEβ. Instruction execution can be described by a long list of conditional operations which are inherently βdisjointβ. Only one of these statements is executed depending on the condition met, and then the instruction fetch statement (iF) is invoked again at the end of the list of concurrent statements. Thus, instruction fetch (iF) and instruction execution statements invoke each other in a loop, which represents the fetch-execute cycle of the SRC.
π Definition β fetch-execute cycle: The continuous loop where the processor fetches an instruction from memory and then executes it, repeating indefinitely until a halt instruction is encountered.
Load-Store Instructions
(op<4..0>= 1) : R [ra] β M [disp] β load register (ld): This instruction loads a register using a displacement address specified by the instruction, i.e., the contents of the memory at the address 'disp' are placed in the register R[ra].
(op<4..0>= 2) : R [ra] β M [rel] β load register relative (ldr): If the operation field 'op' of the instruction decoded is 2, the instruction that is executed is loading a register (target address of this register is specified by the field ra) with memory contents at a relative address, 'rel'.
(op<4..0>= 3) : M [disp] β R [ra] β store register (st): If the op-code is 3, the contents of the register specified by address ra are stored back to the memory at a displacement location 'disp'.
(op<4..0>= 4) : M[rel] β R[ra] β store register relative (str): If the op-code is 4, the contents of the register specified by the target register address ra are stored back to the memory at a relative address location 'rel'.
(op<4..0>= 5) : R [ra] β disp β load displacement address (la): For op-code 5, the displacement address disp is loaded to the register R (specified by the target register address ra).
(op<4..0>= 6) : R [ra] β rel β load relative address (lar): For op-code 6, the relative address rel is loaded to the register R (specified by the target register address ra).
Branch Instructions
(op<4..0>= 8) : (cond : PC β R [rb]) β conditional branch (br): If the op-code is 8, a conditional branch is taken, that is, the program counter is set to the target instruction address specified by rb, if the condition 'cond' is true.
(op<4..0>= 9) : (R [ra] β PC, cond : (PC β R [rb]) ) β branch and link (brl): If the op field is 9, the branch and link instruction is executed, i.e., the contents of the program counter are stored in a register specified by ra field (so control can be returned to it later), and then the conditional branch is taken to a branch target address specified by rb. The branch and link instruction is useful for returning control to the calling program after a procedure call returns.
The conditions that these 'conditional' branches depend on are specified by the field c3 that has 3 bits. When c3<2..0> is equal to one of these values, we substitute the expression on the right-hand side of the ":" in place of cond.
cond := (
c3<2..0>=0 : 0β never: If the c3 field is 0, the branch is never taken.c3<2..0>=1 : 1β always: If the field is 1, branch is taken.c3<2..0>=2 : R [rc]=0β if register is zero: If c3 = 2, a branch is taken if the register rc = 0.c3<2..0>=3 : R [rc] β 0β if register is nonzero: If c3 = 3, a branch is taken if the register rc is not equal to 0.c3<2..0>=4 : R [rc]<31>=0β if positive or zero: If c3 is 4, a branch is taken if the register value in the register specified by rc is greater than or equal to 0.c3<2..0>=5 : R [rc]<31>=1β if negative: If c3 = 5, a branch is taken if the value stored in the register specified by rc is negative.
Arithmetic and Logical Instructions
(op<4..0>=12) : R [ra] β R [rb] + R [rc]: If the op-code is 12, the contents of the registers rb and rc are added, and the result is stored in the register ra.
(op<4..0>=13) : R [ra] β R [rb] + c2<16..0> {sign extended}: If the op-code is 13, the content of the register rb is added with the immediate data in the field c2, and the result is stored in the register ra.
(op<4..0>=14) : R [ra] β R [rb] β R [rc]: If the op-code is 14, the content of the register rc is subtracted from that of rb, and the result is stored in ra.
(op<4..0>=15) : R [ra] β -R [rc]: If the op-code is 15, the content of the register rc is negated, and the result is stored in ra.
(op<4..0>=20) : R [ra] β R [rb] & R [rc]: If the op field equals 20, logical AND of the contents of the registers rb and rc is obtained, and the result is stored in register ra.
(op<4..0>=21) : R [ra] β R [rb] & c2<16..0> {sign extended}: If the op field equals 21, logical AND of the content of the registers rb and the immediate data in the field c2 is obtained, and the result is stored in register ra.
(op<4..0>=22) : R [ra] β R [rb] ~ R [rc]: If the op field equals 22, logical OR of the contents of the registers rb and rc is obtained, and the result is stored in register ra.
(op<4..0>=23) : R [ra] β R [rb] ~ c2<16..0> {sign extended}: If the op field equals 23, logical OR of the content of the registers rb and the immediate data in the field c2 is obtained, and the result is stored in register ra.
(op<4..0>=24) : R [ra] β !R [rc]: If the op-code equals 24, the logical NOT of the content of the register rc is obtained, and the result is stored in ra.
Shift Instructions
(op<4..0>=26): R [ra]<31..0 > β (n Ξ± 0) Β© R [rb] <31..n> β shift right logical: If the op-code is 26, the contents of the register rb are shifted right n bits times. The bits that are shifted out of the register are discarded. 0s are added in their place, i.e., n number of 0s is added (or concatenated) with the register contents. The result is copied to the register ra.
(op<4..0>=27) : R [ra]<31..0 > β (n Ξ± R [rb] <31>) Β© R [rb] <31..n> β shift right arithmetic: For op-code 27, shift arithmetic operation is carried out. In this operation, the contents of the register rb are shifted right n times, with the most significant bit, i.e., bit 31, of the register rb added in their place. The result is copied to the register ra.
(op<4..0>=28) : R [ra]<31..0 > β R [rb] <31-n..0> Β© (n Ξ± 0) β shift left logical: For op-code 28, the contents of the register rb are shifted left n bits times, similar to the shift right instruction. The result is copied to the register ra.
(op<4..0>=29) : R [ra]<31..0 > β R [rb] <31-n..0> Β© R [rb]<31..32-n > β rotate left (circular): The instruction corresponding to op-code 29 is the shift circular instruction. The contents of the register rb are shifted left n times; however, the bits that move out of the register in the shift process are not discarded; instead, these are shifted in from the other end (a circular shifting). The result is stored in register ra.
where n := ((c3<4..0>=0) : R [rc], (c3<4..0>!=0) : c3 <4..0> )
π Notation: Ξ± means replication; Β© means concatenation
Miscellaneous Instructions
(op<4..0>= 0) β No operation (nop): If the op-code is 0, no operation is carried out for that clock period. This instruction is used as a stall in pipelining.
(op<4..0>= 31) : Run β 0 β Halt the processor (Stop): If the op-code is 31, run is set to 0, that is, the processor stops execution.
After one of these disjoint instructions is executed, iF, i.e., instruction Fetch, is carried out once again, and so the fetch-execute cycle continues.
Implementing Register Transfers using Digital Logic Circuits
We have studied the register transfers in the previous sections and how they help in implementing assembly language. In this section we will review how the basic digital logic circuits are used to implement instructions register transfers. The topics covered include:
- A brief (and necessary) review of logic circuits
- Implementing simple register transfers
- Register file implementation using a bus
- Implementing register transfers with mathematical operations
- The Barrel Shifter
- Implementing shift operations
Review of logic circuits
The topics reviewed in this section include: the basic D flip-flop, the n-bit register, the n-to-1 multiplexer, and tri-state buffers.
The basic D flip-flop
A flip-flop is a bi-stable device capable of storing one bit of information. Therefore, flip-flops are used as the building blocks of a computer's memory as well as CPU registers. The most common type, the D flip-flop, is set (i.e., stores a 1) when the data input is high on the leading (also called the positive) edge of the clock; it is reset (i.e., the flip-flop stores a 0) when the data input is 0 on the leading edge of the clock. The clear input will reset the flip-flop on a low input.
The n-bit register
An n-bit register can be formed by grouping n flip-flops together. A register is a device in which a group of flip-flops operate synchronously. A register is useful for storing binary data, as each flip-flop can store one bit. The clock input of the flip-flops is grouped together, as is the enable input. Using the input lines, a binary number can be stored in the register by applying the corresponding logic level to each of the flip-flops simultaneously at the positive edge of the clock. For a 4-bit register, In0 through In3 are the four input lines, Out0 through Out3 are the four output lines, Clk is the clock input, and En is the enable line. The enable input has to be high if the number is to be stored into the register.
The n-to-1 multiplexer
A multiplexer is a device constructed through combinational logic, which takes n inputs and transfers one of them as the output at a time. The input that is selected as the output depends on the selection lines, also called the control input lines. For an n-to-1 multiplexer, there are n input lines, logβn control lines, and 1 output line.
π Example: For a 4-to-1 multiplexer, there are 4 input lines (lines 0 through 3), and 2 select lines (since logβ4 = 2). To transfer the input of line 3 to the output, apply the binary number 11 on the select lines (as the binary number 11 represents the decimal number 3). The output of the multiplexer will then be the input on line 3.
Tri-state buffers
The tri-state buffer, also called the three-state buffer, has a single input, a single output, and an enable line. The input is connected to the output only if it is enabled through the enable line; otherwise, it gives a high impedance output, i.e., it is tri-stated, or electrically disconnected from the input. These buffers are available both in the inverting and the non-inverting form. The inverting tri-state buffers output the 'inverted' input when they are enabled. When the enable input (or the control input) c is low (0), the output is high impedance Z.
π Example: In a 4-bit tri-state buffer unit, if we apply a high on input 3 and 2, and a low on input 1 and 0, we get the output 1100, only when the enable input is high.
Implementing simple register transfers
We now build on our knowledge of the primitive logic circuits to understand how register transfers are implemented. This section covers: simple conditional transfer, the concept of control signals, two-way transfers, connecting multiple registers, buses, and bus implementations.
Simple conditional transfer
In a simple conditional transfer, a condition is checked, and if it is true, the register transfer takes place. Formally, a conditional transfer is represented as:
Cond: RD β RS
This means that if the condition 'Cond' is true, the contents of the register named RS (the source register) are copied to the register RD (the destination register). The output of the source register RS is connected to the input of the destination register RD. The transfer will not take place unless the enable input of the destination register is activated. The 'transfer' is being controlled by the enable line (or the control signal). The condition is, in general, a Boolean expression.
Two-way transfers
In one-way transfer, we could only copy the contents of RS to RD if the condition was met. To achieve two-way transfers, we must also provide a path from the output of the register RD to the input of register RS, enabling us to implement:
Cond1: RD β RSCond2: RS β RD
Connecting multiple registers
To connect more than two registers, one may argue that a connection between the input and output of each be provided. For a scenario with 5 registers, an m-bit register requires two connections of m-wires each. Hence, five m-bit registers in a point-to-point scheme require 20 connections, each with m wires. In general, n registers in a point-to-point scheme require n(n-1) connections. This solution does not scale well for a large number of registers. The solution to this problem is the use of a bus architecture.
Buses
A bus is a device that provides a shared data path to a number of devices that are connected to it via a 'set of wires' or a 'set of conductors'. The modern computer systems extensively employ the bus architecture. Control signals are needed to decide which two entities communicate using the shared medium, i.e., the bus, at any given time. These control signals can be open-collector gate-based, tri-state buffer-based, or they can be implemented using multiplexers.
Register file implementation using the bus architecture
A number of registers can be interconnected to form a register file through the use of a bus. For eight 4-bit registers (R0, R1, ..., R7) interconnected through a 4-bit bus using 4-bit tri-state buffer units, the contents of a particular register can be transferred onto the bus by applying a logical high input on the enable of the corresponding tri-state buffer. For instance, R1out can be used to enable the tri-state buffers of the register R1, and in turn transfer the contents of the register onto the bus. Once the contents of a particular register are on the bus, the contents may be transferred, or read into any other register. More than one register may be written in this manner; however, only one register can write its value on the bus at a given time.
Implementing register transfers with mathematical operations
Frequently we encounter register transfers with mathematical operations, such as (opc=1): R4 β R3 + R2. These mathematical operations may be achieved by introducing appropriate combinational logic. This operation can be implemented in hardware by including a 4-bit adder with the register files connected through the bus. Two more registers are included: one for holding one of the operands (register A), and the other for holding the result (register C) before it is transferred to the destination register.
π Example: Steps for the conditional mathematical transfer (opc=1): R4 β R3 + R2:
- If the condition
opc = 1is met, the contents of R3 are transferred to the temporary register A through the bus. This is done by activatingR3out(loading R3 onto the bus) and simultaneously applying a logical high input toLA(loading the register A). - Enable
R2outto load the contents of register R2 onto the bus. The output of register A is one input to the 4-bit adder; the other input to the adder is the bus itself. As the contents of register R2 are loaded onto the bus, both operands are available to the adder. The output can then be stored to the register C by enabling its write (applying a high input toLC). - Store the resultant number in the destination register R4. This is done by enabling
Cout(writing the number onto the bus) and then enabling the read of register R4 by activating the control signalLR4.
π‘ Why this matters: This example demonstrates the fundamental process by which the CPU executes an arithmetic instruction β moving operands onto a bus, through combinational logic (the adder), and into a temporary register before the final store.
The barrel shifter
Shift operations are frequently used operations, as shifts can be used for the implementation of multiplication and division. A bi-directional shift register with a parallel load capability can be used to perform shift operations. However, the delays in such structures are dependent on the number of shifts to be performed (e.g., a 9-bit shift requires nine clock periods, as one shift is performed per clock cycle). This is not an optimal solution.
The barrel shifter is an alternative, with any number of shifts accomplished during a single clock period. Barrel shifters are constructed by using multiplexers. An n-bit barrel shifter is a combinational circuit implemented using n multiplexers. The barrel provides a shifted copy of the input data at its output. Control inputs are provided to specify the number of times the input data is to be shifted.
π Example: For a barrel shifter that shifts right the input data, the number of shifts depends on the bit pattern applied on the control inputs S0, S1. To apply a single shift, the control signal is 01 on (S1, S0), which is the binary equivalent of the decimal number 1. To apply 2 shifts, control signal 10 is applied. A control input of 11 shifts the number 3 places to the right.
Implementing shift operations
The shift functionality can be incorporated into the register file circuit with the bus architecture by introducing the barrel shifter.
π Example: To perform the operation R4 β ror R3 (2 times):
- Activate
R3out,nb1, andLC. ActivatingR3outloads the contents of register R3 onto the bus. Since the bus is directly connected to the input of the barrel shifter, this number is applied to the input side.nb1andnb0are the barrel shifter's control lines for specifying the number of shifts. Applying a high input tonb1and a low input tonb0will shift the number two places to the right. ActivatingLCwill load the shifted output of the barrel shifter into register C. - Transfer the contents of register C to register R4. This is done by activating the control
Cout, which will load the contents of register C onto the data bus, and by activating the controlLR4, which will let the contents of the bus be written to register R4.
β Key Takeaways
The SRC processor's instruction set is described using behavioral RTL as a list of disjoint conditional operations within the fetch-execute cycle. Each instruction class (load-store, branch, arithmetic/logical, shift, and miscellaneous) has a specific opcode and RTL representation. Hardware implementation of register transfers relies on fundamental digital logic components: D flip-flops (for storage), n-bit registers, multiplexers (for selection), and tri-state buffers (for bus access). The bus architecture is critical for scaling register interconnections, replacing the impractical point-to-point scheme. Complex operations like addition and shifting are implemented by introducing combinational logic (adders) and specialized circuits (barrel shifters) into the bus-based register file, with control signals managing the sequence of data movement.
π§ Quick Revision Questions
- What does the RTL statement
(op<4..0>=12) : R [ra] β R [rb] + R [rc]mean in terms of the instruction it represents and the registers involved? - How does a barrel shifter differ from a traditional shift register in terms of performance, and what is the key advantage?
- Why is a bus architecture preferred over a point-to-point connection scheme when connecting multiple registers?
- What is the purpose of the tri-state buffer in a bus-based register file, and what happens when the enable input is low?
- In the implementation of
(opc=1): R4 β R3 + R2, what are the three steps and which control signals are activated in each step?