Computer Architecture 2022-23
Assessed Exercise 2
Processor Circuit
Introduction
The purpose of this exercise is to learn in detail how a processor works: how a
digital circuit can execute instructions and run programs. The exercise requires
you to understand a working circuit called M1 that implements the Sigma16
architecture, and then to work out how to modify it.
Part 1. Implementing a new instruction: loadxi
Add a new instruction loadxi to the M1 circuit for the Sigma16 architecture.
Modify the datapath and control, as needed, in order to implement the new
instruction in the M1 circuit, and modify the simulation driver so the operation
of the instruction can be observed. Demonstrate the execution of the instruction
using a machine language test program.
The new instruction is load with automatic index increment (the loadxi
instruction). Its format is RX: there are two words; the first word has a 4-bit
opcode f, a 4-bit destination register (the d field), a 4-bit index register (the sa
field), and a 4-bit secondary opcode of f (the sb field). As with all RX instruc-
tions, the second word is a 16-bit constant called the displacement. In assembly
language the instruction is written, for example, as loadxi R1,$12ab[R2].
The effect of executing the instruction is to perform a load, and also to incre-
ment the index register automatically. The effective address is calculated using
the old value of the index register (i.e. the value before it was incremented).
Thus the instruction loadxi R1,$12ab[R2] performs R1 := mem[12ab+R2], R2
:= R2+1.
(Historical note: many real computers have this instruction. The idea is
that computers spend a lot of time iterating over arrays, and in each iteration
you need to load x[i] into a register and also increment i. The loadxi instruction
lets you do this work in one instruction rather than two.)
Test your new instruction using a machine language program that calculates
the sum of the elements of an array X, which contains n elements (this program
is one of the unassessed exercises, and you may use the model solution). To
do this, start with a program that simply calculates the sum using an ordinary
iteration, with an index i that goes from 0 to n − 1. Then change the program
by replacing the load instruction for x[i] by a loadxi instruction, and getting rid
of the explicit add instruction to increment i. Run the modified program on the
circuit, and verify that it gets the correct result.
If you simply remove the add instruction that increments i from the model
solution, the subsequent memory addresses will shift down, which is inconvenient
for comparing the execution of the two versions of the program. Instead of
deleting the instruction, just replace it with something like add R0,R0,R0 which
won’t do anything and will leave all the instructions and data values with the
same address as before.
1