System and Networks (IT)
COMPSCI 4043
Answer ALL 3 Questions
This examination paper is worth a total of 60 marks
CONTINUED OVERLEAF Page 1
1. (a) Express the following in 16-bit two’s complement code, giving your answers in hexadecimal. Show your
working.
i. 180
ii. -30
[4]
(b) Give the range of values that can be represented by a 32-bit two’s complement code (express the
range using powers of 2) and explain why.
[2]
(c) Find two 8-bit codewords, X and Y, such that X+Y overflows if the code being used is unsigned but
does not if it is two’s complement. Now find two codewords, W and Z, such that W+Z overflows in
both codes. Explain your reasoning carefully.
[4]
(d) Write a Sigma16 program that takes an n-element array, X, of unsigned numbers and subtracts 1
from each element, except when the element is already 0. Assume that n is an unsigned variable in
data memory indicating the number of elements in the array. Fully comment your code.
[7]
(e) Referring to your solution for (d), discuss what maximum value of n it would work for, explaining
what factors you are considering.
[3]
For reference, here is part of the instruction set of the Sigma16 CPU.
lea Rd, x[Ra] Rd:= x +Ra
load Rd, x[Ra] Rd:= mem[x +Ra]
store Rd, x[Ra] mem[x +Ra]:=Rd
add Rd,Ra,Rb Rd:= Ra+Rb
sub Rd,Ra,Rb Rd:= Ra-Rb
mul Rd,Ra,Rb Rd:= Ra*Rb
div Rd,Ra,Rb Rd:= Ra/Rb, R15:=Ra mod Rb
and Rd,Ra,Rb Rd:= Ra AND Rb
inv Rd,Ra,Rb Rd:= NOT Ra
or Rd,Ra,Rb Rd:= Ra OR Rb
xor Rd,Ra,Rb Rd:= Ra XOR Rb
cmplt Rd,
Ra,Rb Rd:= RaRb
shiftl Rd,Ra,Rb Rd:=Ra logic shifted left Rb places
shiftr Rd,Ra,Rb Rd:=Ra logic shifted right Rb places
jumpf Rd, x[Ra] If Rd=0 then PC:=x+Ra
jumpt Rd, x[Ra] If Rd<>0 then PC:=x+Ra
jal Rd, x[Ra] Rd:= pc, pc: =x +Ra
trap Rd,Ra,Rb PC:= interrupt handler
jump x[Ra] PC:= x +Ra
CONTINUED OVERLEAF Page 2
2 (a) Distinguish between primary and secondary memory and explain briefly how the CPU accesses data
stored in each. If a user were experiencing problems with the performance of a PC running a modern
operating system using virtual memory, under what circumstances would you recommend increasing the
amount of primary memory Explain your reasoning.
[6]
(b) The following Sigma 16 code is intended to take an 8-element array (only first element is shown) and add
all the elements placing the result in another variable, sum. However, although the code will assemble, it
contains several errors.
i. Draw up a register-use table for the program (suitable for inclusion as comment).
ii. Identify the errors, in each case explain what is wrong, and how you would correct it.
iii. Write out the corrected program.
[6]
(c) Estimate how many cycles the corrected program would take to run.
[4]
(d) In the corrected program estimate the advantage a system with a cache memory would gain if a primary
memory cycle takes 10ns and a cache cycle 1ns.
[4]
LEA R1,1[R0] ;Set R1 to constant 1
ADD R2,R0,R0 ;i:=0
LEA R3,n[R0] ;Set R3 to n
ADD R4,R0,R0 ;sum=0
FORLOOP CMPEQ R5,R2,R3 ;Is i