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

CS1S Computer Systems: Questions and Solutions

2019


1. (a) Convert 1100 0011 to a decimal number, assuming binary representation.

Calculate 128 + 64 + 2 + 1 = 195 by adding the powers of2 corresponding to the positions where there is a 1 bit in the word.

[Problem solving.]

(b) Convert 1100 0011 to a decimal number, assuming two’s complement

representation.

Since the leftmost bit is 1, this is a negative number. Negate it to get a nonnegative number. To negate, first invert it giving 0011 1100. Then increment it, giving 0011 1101. Now this result is nonnegative, so its binary representation is the same as its two’s complement value; this is 32 + 16 + 8 + 4 + 1 = 61. Since the negation ofthe original word is 61, the answer is -61.

[Problem solving. 1 mark for identifying it as negative; 2 marks for negation.]

(c) Translate the statement  a := b*c – d/b into Sigma16 assembly language, assuming that a, b, c, and d are 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.

[Problem solving, requires understanding usage ofregisters, variables, and basic instructions 2 marks for loads and store, 1 mark for arithmetic ]

(d) In the following program, variables k, i and n are integers, and x is an array of signed integers containing n elements.  Suppose the program is executed with  these initial values:

n = 7

x = [9, -2, 13, 0, 45, -8, 7]

After the program executes, what are the values of k and x?



k := 0;

for i := 0 to n-1 do

{ if x[i] < 0

then { x[i] := -x[i]; }

else { k := k+1; } }

k = 5

x = [9, 2, 13, 0, 45, 8, 7]

(k is the number ofnonnegative numbers in the array, and each element ofx that was negative is negated, although it isn’t required to say that.)

[Problem solving 1 mark for value of k, 1 mark for the array.]

(e) Translate the program in part (d) into low level language.   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.)

k := 0;

i := 0;

if not (i then goto done;

if not (x[i]<0) then goto nonneg;

x[i] goto k := i := goto

:= -x[i]; afterif; k+1;

i+1; forloop;

[Problem solving. 1 mark for variables, 2 marks for loop, 2 marks for conditional.]