K ALU Report
K ALU Report
• Assumptions
- Word length of our processor is 32 bits.
- All registers and memory elements have 32 bit data.
- The address line of the memory is also 32 bit.
- The processor has a single-cycle instruction execution unit i.e., every instruction will take one
clock cycle to complete execution. There is no pipelining.
• Instruction Encodings
Register Addressing Mode
Instruction Encoding Type: R-Format (Register Addressing Mode)
Instructions having the same opcode can be differentiated by the bits in the 𝑓𝑢𝑛𝑐𝑡 field.
opcode rs imm
opcode rs rt imm
opcode address
b 000 111 L
bl 001 000 L
opcode rs offset
br 001 011 rs —
bz 001 101 rs L
• Future Extensions
The opcode field is given 6 bits in the instruction encoding. This means that the KGP-RISC
architecture can have 64 instructions with different opcodes. 15 of the 64 opcodes are used
already. Therefore, the ISA can be extended to include 49 new instructions with different
opcodes. Secondly, for the instructions belonging to R-type formatting, 10 bits are reserved for
the funct field that identifies the function type for similar types of arithmetic instructions. This
means that for each opcode, 1024 distinct R-type instructions can be written in the ISA. 3 opcodes
are used already in the R-type instructions for which respectively 4, 3, 3 instructions are written
with different funct fields. So for the already existing opcodes in the R-type instructions, a
total of 3062 new R-type instructions can be written without using any new opcodes. Adding
to this number in the best case if all the 49 remaining opcodes are used for R-type instructions,
since each opcode can support 1024 R-type instructions, a maximum of 53238 new R-type
instructions can be included in the architecture.
• Datapath Elements
The various datapath elements that will be needed in the processor that implements the
KGP-RISC ISA are as follows.
– Program Counter – Instruction Memory – Register File
– Arithmetic Logic Unit – Data Memory – Sign Extension Modules
– Main Controller – ALU Control Unit – 32-Bit Adder
– Multiplexors – Concatenation Modules – Zero Padding Modules
Multiplexors of different bus widths and number of inputs will be needed. Similarly, different sign
extension modules for different input bus widths will be needed. Besides these, some other helper
modules may also be needed to modularize the hardware design (like a special module that
determines the success of a branch instruction). These modules will become absolutely clear in
the datapath diagram of the single cycle execution unit.
• Processor Design for Single Cycle Execution Unit
The next page shows the complete datapath of the Single Cycle Execution RISC Architecture
with the control signals (highlighted in blue). All the datapath elements are clearly shown.
Following that, we have highlighted (in bold red) the datapath for each of the instructions that
shows the various phases of single cycle execution, from instruction fetch to write-data, that the
processor must go through to execute these instructions successfully. These independent
datapath diagrams for each instruction will make the functionality of the respective instructions of
KGP-RISC ISA much more clearer.
Single Cycle Execution Unit for KGP-RISC Architecture
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ /RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•/
Text5 C[25..21] rs
PC
Read Reg1
Read Data1
•.
32
/ . Zero .
•
Read
C[20..16] rt
Address 5
/ • Read Reg2 Read Data2
•.
••
0 . 32
Instruction M
32-Bit
ALU
Result . / Address
C[31..0] •TText
•• Register
1 U
32
2 File 4
X Carry Read Data /
Instruction •ex 0
M 5
3
32
/ . 32
Memory t U / Write Reg
2
/ Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
32
16 /
16 Text C[15..0] 32
/ • /
16-32 Sign
Extension /
/
32
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for R-Type Instructions
( add, and, xor, comp, shllv, shrlv, shrav )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •
. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•x
e
0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
7 Memory
ALU 1U
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for R-Type Instructions
( shll, shrl, shra )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
26
/ / RegDest
2
• BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction •ex 0
M 3
2
.
t Write Data
Memory U Write Reg
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
Text C[15..0] 16
•
16 16-32 Sign 32
/ / Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Non-Memory Based I-Type Instructions
( addi, compi )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
•
C[25..21] rs
ALUResult[31]
Text
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction •x
e
0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
Text C[15..0] 16
•
16 16-32 Sign 32
/ / Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Memory-Based I-Type Instructions
( lw )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
•
Text C[25..21] rs
ALUResult[31]
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
•
Address C[20..16] rt
Instruction
Read Reg2 Read Data2
• .
0
M
32-Bit
ALU
Result ••
.
.
Address
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction •x
e
0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Memory-Based I-Type Instructions
( sw )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
•
Address C[20..16] rt
Instruction
Read Reg2 Read Data2
• .
0
M
32-Bit
ALU
Result ••
.
.
Address
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in Pseudo-Direct Addressing Mode
(b)
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ /RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in Pseudo-Direct Addressing Mode
( bl )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction •x
e
0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
ALU 7 1U
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in Pseudo-Direct Addressing Mode
( bcy, bncy ) : Successful Branching
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
32 (PC+4)[31..28]
/ Adder
U
X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
ALU 7 1U
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in Pseudo-Direct Addressing Mode
( bcy, bncy ) : Unsuccessful Branching
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
(PC+4)[31..28] /
U
Adder
32 X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
•
C[25..21] rs
ALUResult[31]
Text
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in PC-Relative Addressing Mode
( br )
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
C[25..0] Text
28 32 • 1
4 SignExtd M
32-Bit
(PC+4)[31..28] /
U
Adder
32 X
FOUR / •
. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction
•ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in PC-Relative Addressing Mode
( bltz, bz, bnz ) : Unsuccessful Branching
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
28 32 • 1
•
C[25..0] Text M
Left Shift 2 / Concatenate / U
X
32-Bit
Adder • 21
/
C[20..0] Left Shift 2 +
23-32 1
0
4 SignExtd M
32-Bit
(PC+4)[31..28] /
U
Adder
32 X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /3
32 / 32 / Control /
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2
Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• 2
Register
1 U
X Carry Read Data
File 4
Instruction •ex 0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
Datapath for Instructions in PC-Relative Addressing Mode
( bltz, bz, bnz ) : Successful Branching
32
/32
/
BranchReg
32
/ 1
• BranchCarryType
M
U
• BranchCarryDep 32 0
X
/ 1
M
U
X
0
28 32 • 1
•
C[25..0] Text M
Left Shift 2 / Concatenate / U
X
32-Bit
Adder • 21
/
C[20..0] Left Shift 2
+ 23-32 1
0
4 SignExtd M
32-Bit
(PC+4)[31..28] /
U
Adder
32 X
FOUR / •. •
Text 0
•
26 2
/ / RegDest BranchNoRegNoCond
BranchComp
2
Mem2RegData /
32 / 32 / Control /
3
ALUOp
MemWrite 3
/
C[31..26]
ALUSrc
RegWrite Comp
2
6 BranchCompType / Branch
Success
/
ALUResult[31]
•
Text C[25..21] rs
PC
Read Reg1
Read Data1
• . . Zero .
•
Read
Address
•
C[20..16] rt
Read Reg2 Read Data2
• .
••
0 32-Bit .
M Result Address
Instruction ALU .
C[31..0] •TText
•• Register
1 U
X Carry Read Data
2 File 4
Instruction •x
e
0
M 3
2
.
Memory t U Write Reg Write Data
X ZERO Data
RegID($ra) 1 Write Data 2M
Memory
7 1U
ALU
Control / 0X
16 Text C[15..0] 16 32
/ • /
16-32 Sign
Extension /
10
• C[9..0]
/ 32
/
6 6-32 32
C[15..10]
/ Pad Leading
Zeroes
/
21 C[20..0] 32
21-32 Sign
/ Extension /
• Design of Arithmetic Logic Unit
Following is the design of the 32-bit ALU (control lines are shown in blue color). The adder used is
a 32-bit Carry Look Ahead Adder and the combinational circuit used for implementing the shift
instructions is a 32-bit Barrel Shifter. The AND and XOR instructions are trivial implementations
of bitwise-AND and bitwise-XOR using an array of AND and XOR gates.
Branch
OPCODE BranchReg BranchCarryType BranchCarryDep BranchComp Mem2RegData
NoRegNoCond
000 000 0 X 0 0 0 00
000 001 0 X 0 0 0 00
000 010 0 X 0 0 0 00
000 011 0 X 0 0 0 00
000 100 0 X 0 0 0 00
000 101 0 X 0 0 0 01
000 110 0 X 0 0 0 XX
000 111 0 X 0 1 0 XX
001 000 0 X 0 1 0 10
001 001 0 1 1 0 0 XX
001 010 0 0 1 0 0 XX
001 011 1 X 0 0 0 XX
001 100 0 X 0 0 1 XX
001 101 0 X 0 0 1 XX
001 110 0 X 0 0 1 XX
ALU Controller
— XXXXXXXXXX — 0111111
— XXXXXXXXXX — 0111111
— XXXXXXXXXX — 0111111
bnz, bz,
110 XXXXXXXXXX Addition 0000000
bltz, lw, sw
b, bl,
000 XXXXXXXXXX — 0111111
bcy, bncy
• Design of Memory Modules
The processor consists of two memory modules — Instruction Memory and Data Memory.
Since, the processor must not be permitted to overwrite the instruction memory, it is implemented
as a 32-bit enabled Single Port ROM (Read-Only Memory) (left hand side picture). The module
takes as input a 32-bit address and emits the 32-bit binary instruction stored at that address.
The processor must have both read and write access to the data memory and hence it is
implemented as a 32-bit enabled Single Port RAM (Random-Access Memory) (right hand side
picture). Note that though the processor has both read and write access to the data memory, this
access is moderated by the control signals to prevent unwanted write operations on the data
memory. Please refer to the truth-table to learn more about the instructions that allow the
respective access.
For reading, the module takes as input a 32-bit address and emits the 32-bit data that is stored at
that address in the memory. For writing, the write enabling port of the module should be active. It
takes as input a 32-bit address and 32-bit data and writes the data to that address in the memory.
Unlike in MIPS32, we have not made any special distinction between callee-saved registers
($s<i>), argument registers ($a<i>) and temporaries ($t<i>). All registers can be used for all
purposes, except two special registers $zero and $ra.
$zero stores a constant value of 0. Therefore the register-write-enabled instructions with $zero as
the destination register (rd) may not give the desired result.
# Value of $0 – 0
addi $0, 100
# Value of $0 – 0
# Mem[4] – 123
lw $0, 4($0)
# Value of $0 – 0
Though these instructions are logically illegal because the destination register is read-only, since
we have not developed any interrupt or exception mechanism in our custom ISA, the programmer
might be unaware of this bug.
CAUTION: The programmer should never use $zero as the destination register in
register-write-enabled instructions.
Similarly the use of $ra should also be restricted to bl and br instructions only. If $ra is
overwritten explicitly (say addi $31, 100) and as opposed to only internally by the bl instruction,
the function call mechanism in the code might get disrupted, and that might become extremely
difficult to debug. But if the programmer still has to jump to some custom address using a br but
not the bl instruction, he can use any general purpose register ($1 – $30), copy the value of $ra to
that and can do whatever with that register.
# Value of $1 – 0
add $1, $31
addi $1, 1200 # addi $31, 1200 X
br $1 # br $31 X