Lab 1 CompArch
Lab 1 CompArch
ALU
Submitted By :- Nilay K Wani (2022AAPS0444G)
1|Lab1
Exercise 1.1.1: Implement Instruction memory in Verilog.
The instruction memory has two inputs a 32-bit Input coming from PC
and a 1-bit reset. It has one 32-bit output indicating the output
instruction code. According to the specifications when reset is logic 0
the Instruction memory should be initialized with specific data. This
initialization is necessary to write the instruction codes into the
memory. When reset is logic 1 the instruction memory should output
the 32-bit instruction code corresponding to the 32-bit input address.
The partial code for the Instruction memory is shown below. Please
read the comments for a better understanding of the design.
2|Lab1
reg [7:0] Mem [36:0]; defines byte addressable memory with 37
locations.
Copy the image of the completed Instruction memory module.?
3|Lab1
Answer:
4|Lab1
Copy the image of the Testbench code?
Answer:
Copy the image of the waveform window that is generated for your
Testbench? (Change display radix to Hexadecimal)
5|Lab1
Answer:
6|Lab1
The data read out from Instruction memory is 32-bits. Then what is the
reason for defining Mem as [7:0] Mem [No. of locations] instead of
[31:0] Mem [No. of locations]
Answer: The memory is organized into bytes (8 bits) because each
instruction is 32 bits, requiring 4 bytes. The PC increments by 4 to fetch
the next instruction.
Exercise 1.1.3 Implement and test (using test bench) the Instruction
fetch unit by instantiating the Instruction memory block. (As part of
7|Lab1
Instruction fetch test bench enable reset initially and then generate
continuous clock).
The instruction fetch unit has clock and reset pins as inputs and
Instruction code as output. Internally it has a PC register which holds
the address of current instruction. It also has an adder to compute PC +
4. The partial code for the instruction fetch unit (without instantiation
of instruction memory) is shown below.
There is an error in the code above. What is the error and what should
be done to solve this error?
Answer: Output must be recorded in a wire format not reg as it is
defined somewhere else as wire format.
Copy the image of the completed Instruction fetch module?
8|Lab1
Answer:
Copy the image of the waveform window that is generated for your
Testbench? (Change display radix to Hexadecimal).
Answer:
9|Lab1
Exercise 1.2 Design of simple ALU.
ALU (Arithmetic and Logical unit) is an important component of any
processor. ALU performs different arithmetic and logical operations
depending on the control lines. In this section, you will be implementing
a simple ALU for a given set of specifications.
ALU Specifications:
This ALU has two 32-bit operands and 4 control lines as inputs. It has
two outputs a 32-bit ALU result and a Zero indicator which becomes
logic 1 if and only if the 32-bit ALU result is Zero. The ALU has to
perform different functions according to the value of 4 control lines.
The block diagram of ALU along with the mapping of control lines to
functions performed is shown below.
10 | L a b 1
your Verilog code. Answer:
Write the test bench to test the ALU. Your test bench should have 7
different test patterns as mentioned below. (Assume test pattern
changes after every 20 time units)
11 | L a b 1
Paste the image of your test bench with the above test cases.
Answer:
For easy viewing of the testbench waveforms where signals are multi-
bit, you can change the view in the simulation window to
decimal/hexadecimal mode. Right-click on all the input output signals
select Radix and then click on signed decimal/hexadecimal.
12 | L a b 1
Copy the image of the waveform window that is generated for your
Testbench? (Change display radix to Hexadecimal).
Answer:
13 | L a b 1
Do you have a synthesisable design? If not write a synthesisable Verilog
description of your design.
Use the Xilinx Vivado, synthesise, and obtain the RTL. Verify the RTL
with your architecture.
Note down your observation below:
Yes my design is synthesizable. Reduction OR is implemented by the
ALU RTL to do a bitwise OR. Output 1 is obtained if any bits are set in
vector. If all the bits are 0 in vector then O/p is 0. It sets the zero flag.
14 | L a b 1
15 | L a b 1