EXP10
EXP10
EXP10
10.1 Objectives
In this experiment we are going to design the Verilog HDL control sequence for a simple
computer (SIMCOMP). The SIMCOMP is a very small computer to give the students practice in
the ideas of designing a simple CPU with the Verilog HDL notation.
1
10.4 Theory
10.4.1 Basic Computer Model - Von Neumann Model
Von Neumann computer systems contain three main building blocks: the central
processing unit (CPU), memory, and input/output devices (I/O). These three
components are connected together using the system bus. The most prominent items
within the CPU are the registers: they can be manipulated directly by a computer
program, see Figure 1:
Function of the Von Neumann Component:
Memory: Storage of information (data/program)
Processing Unit: Computation/Processing of Information
Input: Means of getting information into the computer. e.g., keyboard, mouse
Output: Means of getting information out of the computer. e.g., printer, monitor
Control Unit: Makes sure that all the other parts perform their tasks correctly and at
the correct time.
2
2) The data register (MDR) acts as a buffer between the CPU and main memory. It
is used as an input operand register with the accumulator.
3) The instruction register (IR) holds the opcode of the current instruction.
4) The address register (MAR) holds the address of the memory in which the
operand resides.
5) The program counter (PC) holds the address of the next instruction to be
fetched/execution.
Additional addressable registers can be provided for storing operands and address.
This can be viewed as replacing the single accumulator by a set of registers. If the
registers are used for many purposes, the resulting computer is said to have general
register organization. In the case of processor registers, a register is selected by the
multiplexers that form the buses.
3
or memory addresses contain the operands.
3) Fetch operands from memory if necessary:
If any operands are memory addresses, initiate memory read cycles to read them
into CPU registers. If an operand is in memory, not a register, then the memory
address of the operand is known as the effective address, or EA for short. The
fetching of an operand can therefore be denoted as Register ← Memory [EA]. On
today's computers, CPUs are much faster than memory, so operand fetching
usually takes multiple CPU clock cycles to complete.
4) Execute:
Perform the function of the instruction. If arithmetic or logic instruction, utilize
the ALU circuits to carry out the operation on data in registers. This is the only
stage of the instruction cycle that is useful from the perspective of the end user.
Everything else is overhead required to make the execute stage happen. One of
the major goals of CPU design is to eliminate overhead and spend a higher
percentage of the time in the execute stage.
5) Store result in memory if necessary:
If destination is a memory address, initiate a memory write cycle to transfer the
result from the CPU to memory. Depending on the situation, the CPU may or may
not have to wait until this operation completes. If the next instruction does not
need to access the memory chip where the result is stored, it can proceed with the
next instruction while the memory unit is carrying out the write operation.
Below is an example of a full instruction cycle which uses memory addresses
for all three operands:
1- Mull product, x, y
2- Fetch the instruction code from Memory [PC]
3- Decode the instruction. This reveals that it's a multiply instruction, and that
the operands are memory locations x, y, and product.
4- Fetch x and y from memory.
5- Multiply x and y, storing the result in a CPU register.
6- Save the result from the CPU to memory location product.
4
10.4.5 Addressing Modes
The term addressing modes refers to the way in which the operand of an instruction is
specified. Information contained in the instruction code is the value of the operand or
the address of the result/operand.
5
The opcodes are:
1) You must write the basic code shown in Figure 4 at the last page of this experiment in your own
Quartus II file.
2) You have to trace the basic code manually so that you can understand what does the code do. Use
the following table:
Line # Code Description of what is done
6 reg [15:0] Memory [0:63]
7 reg [2:0] state
13 Memory [10] = 16’h3020
14 Memory [11] = 16’h7021
15 Memory [12] = 16’hB014
18 Memory [32] = 16’d7
19 Memory [32] = 16’d7
22 PC = 10; state = 0
29 MAR <= PC
30 state = 1
33 IR <= Memory [MAR]
34 PC <= PC + 1
35 state = 2
38 MAR <= IR [11:0]
39 state = 3
42 state = 4
43 case (IR [15:12])
load: MBR <= Memory
44
[MAR]
6
45 add: MBR <= Memory [MAR]
46 store: MBR <= AC
52 AC <= AC + MBR
56 AC <= MBR
60 Memory [MAR] <= MBR
Table 2
3) You have to summarize the objective of Program#1 above, then repeat for Program #2
Instructions
Memory location Instruction assembly Instruction machine code in Hex
10 Load [32] 0011-0000-0010-0000b 16'h3020
11 Add [33] 0111-0000-0010-0001b 16'h7021h
12 Store [20] 1011-0000-0001-0100b 16'hB014h
Data
32 Data 7 Memory [32] 16'h7
33 Data 5 Memory [32] 16'd5
Table 3
7
Task 2: Write the General form of the instruction set for Prog #1
Task 3: Trace the Modified code as was done in the prelab but this time using
the waveforms
Instructions
Memory Destination Source
Instruction Instruction set code in binary in Hex
location register Register/Memory
10 Load R1 3 0011-0001-0000-0011b 16'h3103
11 Load R2 4 0011-0010-0000-0100b 16'h3204
12 Add R1 R1, R2 0111-0101-1000-0000b 16'h7580
13 Store R1 5 1011-0001-0000-0101b 16'hB105
8
Data
3 Data A Memory [3] 16'hA
4 Data 6 Memory [4] 16'd6
Table 5
Task 5: Write the General form of the instruction set for SIMCOMP2.
Task 6: Trace SIMCOMP2 code using the waveforms.
Task 7: Add immediate addressing to the SIMCOMP2:
If bit (IR [11]) is a one in a Load, the last eight bits are not an address but an operand. The
operand is in the range -128 to 127.
If immediate addressing is used in a LOAD, the operand is loaded into the register.
Load R1, 8
R1 ← 8
Simulate the following test with handwritten comments explaining what you are doing.
PC = 10
Memory [10]: Load R1,3 // Load immediate
Memory [11]: Load R2, -4 //Use 2's complement to represent (-4) Memory [12] Add R1, R1, R1
Memory [13]: Store R1,5
Instructions
Memory Destination Source
Instruction Instruction set code in binary in Hex
location register Register/Memory
Load
10 R1 3 0011-1001-0000-0011b 16'h3903
Immediate
Load
11 R2 -4 0011-1010-1111-1100b 16'h3AFC
Immediate
12 Add R1 R1, R2 0111-0101-1000-0000b 16'h7580
13 Store R1 5 1011-0001-0000-0101b 16'hB105
Data
3 Data A Memory [3] 16'hA
4 Data 6 Memory [4] 16'd6
Table 6
9
MBR <= - (~ (IR [7:0]) + 1)
Task 8: Write the General form of the instruction set for Prog #2 with
immediate load
10
At the end of this experiment, you should have two files:
1- An Accumulator Based Simple Computer with 4 instructions as in program 1.
2- A register based simple computer with 3 opcodes (noting that the load opcode can be
immediate or normal) as in program 2.
2. Modify the program in the first part of the post-lab to include the jump instruction
with opcode (jump=4'b1001) and change code to run this code below. (Write the
instruction format)
3. Modify the previous program making it sum 10 elements using a jump (loop)
opcode to sum the 10 elements.
Instructions
Memory Destination Source
Instruction Instruction set code in binary in Hex
location register Register/Memory
10 Load R1 3
11 Load R2 4
12 Load R3 -9
13 Add R1 R1, R2, R3
14 Store R1 5
Table 7
11