Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS1S Computer Systems: Questions and Solutions

2018

1. (a) Convert 1010 0010 to a decimal number, assuming binary representation.

Calculate 128 + 32 + 2 = 162 by adding the powers of2 corresponding to the positions where there is a 1 bit in the word. [Problem solving.]

(b) Convert 1010 0010 to a decimal number, assuming two’s complement

Since the leftmost bit is 1, this is a negative number. Negate it to get a nonnegative number. To negate, first invert it giving 0101 1101. Then increment it, giving 0101 1110. Now this result is nonnegative so its binary representation is the same as its two’s complement value; this is 64 + 16 + 8 + 4 + 2 = 94. Since the negation ofthe original word is 94, the answer is -94. [Problem solving. 1 mark for identifying it as negative; 2 marks for negation.]

(c) Translate the statement  a := b - c*d into Sigma16 assembly language,     assuming that a, b, c, d are signed integer variables.  You do not need to write a   complete program, and you don’t need to write data statements for the variables. Just translate this one statement.

(d) Translate the following high level language program fragment into low level         language.   The variables sum, i and n are signed integers, and x is an array of       signed integers containing n elements.  You do not need to define the variables or array, just translate the program code.   (The low level language contains               assignment statements, goto statements, and statements ofthe form if b then goto label, where b is a Boolean expression.)

sum := 0


i := 0

while i < n && x[i] > 0 do

sum := sum + x[i]

i := i + 1

sum := 0

i := 0

loop:

if i >= n then goto done

if x[i] <= 0 then goto done

sum := sum + x[i]

i := i + 1

goto loop

done:

[Problem solving, requires understanding while loop translation.]

(e) Translate the program in part (d) into a complete program in Sigma16 assembly


At termination, sum = 7 + 2 = 9

; R4 = constant 1

; R5 = x[i]

; Define variables


n data 4

sum data 0

x data 7

data 2

data 0

data 5

[Problem solving, requires understanding ofthe instruction set, conditionals, indexed addressing and loops. 3 marks for initialization and store, 5 marks for loop, 2 marks for array access]


2. (a) Give the truth tables for the following logic gates: and2, or2, xor2.


a

b

and2 a b

or2 a b

xor2 a b

0

0

0

0

0

0

1

0

1

1

1

0

0

1

1

1

1

1

1

0

[Bookwork. 1 mark for each gate.]

(b) Consider a circuit that takes two inputs a, b.  It produces one output, x, which is 1


a

b

x

0

0

1

0

1

0

1

0

0

1

1

1


There are many solutions, including