2013 examination paper - Department of Computer Science and

advertisement
BIRKBECK
(University of London)
BSc/FD Examination for Internal Students
Department of Computer Science and Information Systems
Introduction to Computer Systems
(BUCI008H4 - value: 15 credits)
Date and time of Examination: Wednesday 5th June 2013 at 10.00 am
Duration of Paper: 2 hours
Calculators are not allowed
Answer ALL TEN questions. Each question is worth 10 marks.
The paper is divided into two sections: Section A (40 marks) and Section
B (60 marks). Answer each section in a different Answer Book. Do not
include in the same Answer Book answers to questions in two or more
sections.
Where appropriate, include a justification or an explanation for each
answer.
This paper is not prior disclosed.
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
1 of 10
Section A: Boolean Operations and Number Representations (40
marks)
1. Show your working in all parts of this question.
a) Add the two binary numbers 1001 and 1101. Show the result in binary
form.
(2 marks)
b) Multiply the two binary numbers 1101 and 11. Show the result in
binary form.
(2 marks)
c) Convert the following two binary numbers into hexadecimal numbers:
11101010 and 111010.
(2 marks)
d) Express the following two decimal numbers in three bit excess
notation: 3 and -2.
(2 marks)
e) Add the following two hexadecimal numbers: 7 and 8. Show the result
in hexadecimal form.
(2 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
2 of 10
2. (a) A number is a binary fraction if it can be written in the form a/b
such that a is an integer and b is a power of 2. For example 5 is a binary
fraction for which a = 5 and b = 1 = 2^(0). Which of the following
numbers are binary fractions and which are not binary fractions?
i) Decimal 37
ii) Binary 10.1
iii) Decimal 7/3
iv) Binary 0.11
(2 marks)
b) The Brookshear representation for a binary fraction x consists of 8 bits,
labelled s, e1, e2, e3, m1, m2, m3, m4 from left to right. If x is zero then
all 8 bits are zero. Next, suppose that x is not zero. The bit s is 1 if x is
strictly negative and 0 if x is strictly positive. To obtain the remaining
bits, x is written in the form
2^(r) * 0.t
where r is an integer and t is a bit string with the left most bit equal to 1.
Then e1, e2, e3 specify the three bit excess notation for r and m1, m2,
m3, m4 are the left most four bits of t.
i) Obtain the Brookshear floating point representation for the decimal
integer 7. Show your working.
(3 marks)
ii) Obtain the decimal number that has the Brookshear floating point
representation 01101010. Show your working.
(3 marks)
c) Find the largest positive decimal number that can be expressed exactly
in Brookshear floating point notation, i.e. without any truncation error.
Explain how you obtained the answer.
(2 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
3 of 10
3. a) Consider the following four truth tables in which 0 stands for False
and 1 stands for True.
A
0
0
1
1
B
0
1
0
1
T1(A,B)
0
0
0
1
A
0
0
1
1
B
0
1
0
1
T2(A,B)
0
1
1
0
A
0
0
1
1
B
0
1
0
1
T3(A,B)
1
1
0
0
A
0
0
1
1
B
0
1
0
1
T4(A,B)
1
0
0
0
The four truth tables are for the Boolean operations NOT(A), A XOR B
(XOR is exclusive or), A AND B and NOT(A OR B). State which table
T1, T2, T3, T4 corresponds to which operation.
(4 marks)
b) Consider the following truth table for the Boolean expression
A IMPLIES B.
A
0
0
1
1
B
0
1
0
1
A IMPLIES B
1
1
0
1
Use the Boolean operations NOT, AND and the Boolean variables A, B
to construct a Boolean expression which has the same truth table as A
IMPLIES B.
Hint: look at the third row of the truth table for A IMPLIES B, and note
that it is the only row for which the value of A IMPLIES B is 0.
(2 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
4 of 10
c) Evaluate the following two Boolean expressions, given that A = 0
(False), B = 1 (True) and C = 1 (True).
i) (A AND B) OR (B AND C)
(2 marks)
ii) (NOT(A) OR NOT(C)) AND B
(2 marks)
In both answers, show your working.
4. a) Evaluate the following expressions, under the assumption that x = 4
and y = 7. Note that = = is a test for equality.
i) x > y
ii) (x < y) AND (x > 0)
iii) x = = y
iv) NOT(x = = 0)
(4 marks)
b) Let A1, A2 be binary bits. The sum of A1 and A2 is expressed as a
single bit B and a carry bit C. The table for B is as follows.
A1
0
0
1
1
A2
0
1
0
1
B
0
1
1
0
Write out the table for the carry bit C. Show how the truth tables for B
and C can be used to find the result of adding the binary numbers 11 and
1.
(6 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
5 of 10
Section B: Programming and Structure of a Computer (60 marks)
5. a) Convert the following two decimal integers to binary integers: 11,
42.
(2 marks)
b) Convert the following two binary integers to decimal integers: 11,
1101.
(2 marks)
c) Consider the following pseudo code algorithm for finding the binary
number corresponding to a non-negative decimal integer m. Comments
are in the form /* comment */. Prepend places a bit at the beginning of a
bit string, for example Prepend[0, {1, 1}] has the value {0, 1, 1}.
Input: non-negative integer m
Output: bit string b that specifies the binary representation of m.
1. If[m = = 0, Output {0}; Halt]
2. b = {};
/* empty bit string*/
3. While (m > 0)
4.
Divide m by 2 to give quotient q and remainder r;
5.
m = q;
6.
b = Prepend[r, b];
/* r followed by b */
7. EndWhile;
8. Output b;
9. Halt;
Describe in detail the action of the pseudo code algorithm for m = 3.
(4 marks)
d) Describe how the algorithm in part (c) of this question can be modified
to produce a new algorithm that finds the hexadecimal number
corresponding to a non-negative decimal integer m. Explicit calculations
with hexadecimal digits are not required.
(2 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
6 of 10
6. The following table describes instructions of length 16 bits, made by
concatenating an op-code and an operand. The first 4 bits record the opcode. The remaining 12 bits record the operand. Four bits are required to
specify a register R and 8 bits are required to specify a memory location
XY. Each register holds 8 bits and each memory location holds 8 bits.
Op- Operand Description
code
1
RXY
Load register R with the bit pattern at memory cell
XY.
2
RXY
Load register R with the bit pattern XY.
3
RXY
Store the bit pattern in register R at memory cell XY.
4
0RS
Move the bit pattern in register R to register S.
5
RST
Add (two’s complement) the bit patterns in registers R
and S. Put the result in register T.
6
RST
Add (floating point) the bit patterns in registers R and
S. Put the result in register T.
7
RST
Or the bit patterns in registers S and T. Put the result in
register R.
8
RST
And the bit patterns in registers S and T. Put the result
in register R.
9
RST
Exclusive Or the bit patterns in registers S and T. Put
the result in register R.
A
R0X
Rotate the bit pattern in register R one bit to the right
X times.
B
RXY
Jump to the instruction in memory cell XY if the bit
pattern in register R is equal to the bit pattern in
register 0.
C
000
Halt.
Each 16 bit instruction is coded by four hexadecimal digits. For example,
the four hexadecimal digits 37A9 specify an instruction with op-code 3,
in which the “7” refers to register 7 and “A9” refers to the memory cell
A9. The registers are numbered in hexadecimal from 0 to F.
All memory addresses in this question are given in hexadecimal notation.
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
7 of 10
a) Memory cells 90 and 91 each hold an integer in 8 bits two’s
complement notation. The following program halts with 1 in register 1 if
the two integers are equal and it halts with 0 in register 1 otherwise.
25C0
3592
2500
3593
2101
1290
1091
B292
2100
C000
Use the table at the beginning of this question to describe the action
carried out by each instruction. For example, 25C0 loads the bit pattern
C0 in register 5 and 3592 stores the contents of register 5 in memory cell
92.
(4 marks)
b) Describe in words the action of the program shown in part (a) of this
question. A high level description is required, suitable for a reader who
knows about registers, memory and instructions but who instructions but
who finds the list of instructions in part (a) of this question unilluminating.
(6 marks)
7. a) Every integer strictly greater than 0 can be written as a sum of
distinct powers of 2. For example, the decimal integers 1,4 and 7 can be
expressed as sums of powers of 2 in the following ways:
i) 1 = 2^(0)
ii) 4 = 2^(2)
iii) 7 = 2^(2)+2^(1)+2^(0)
Explain how this property ensures that every integer strictly greater than
0 can be expressed in binary form. What is the connection between the
binary digits for an integer and the expression of that integer as a sum of
powers of 2. Illustrate your answer using the number 7.
(4 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
8 of 10
b) Let n be an integer strictly greater than 0. It is required to find an
integer k such that
2^(k) <= n and 2^(k+1) > n.
For example, if n = 5, then k = 2 because 4 <= 5 and 8 > 5. An algorithm
to find k is specified as follows: begin with k = 0. Test to see if 2^(k) <=
n. If the test returns True then increase k by 1 and repeat the test. If the
test returns False then output k-1 and halt. Write out a pseudo code
version of this algorithm that includes a while loop.
(4 marks)
c) Explain how the algorithm in part (b) of this question can be used to
find the length of the binary representation of a strictly positive integer.
The length is by definition the number of bits in the representation,
assuming that the left most bit is 1. For example the length of 1101 is 4.
(2 marks)
8. (a) Define a pointer.
(2 marks)
(b) It is required to store a list of items in memory. The items are of
varying size, and it may be necessary to add or remove items at a later
date. Give one reason why it is inefficient to insist that the items be stored
side by side in memory.
(2 marks)
(c) Suppose that it is no longer required to store the items in the list
referred to in part (b) of this question side by side in memory. Explain
how the items can be stored in memory as a linked list. Include in your
explanation an example with a list consisting of three items. Give explicit
values for the pointers and the addresses of the items in your example.
(4 marks)
(d) Describe the process of deleting the first item from your example of a
linked list in part (c) of this question.
(2 marks)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
9 of 10
9. (a) Draw a labelled diagram showing the CPU and the main memory of
a computer. The diagram should show the high level structure of the CPU
and the link between the CPU and the main memory.
(4 marks)
b) Describe the machine cycle, i.e. the sequence of three actions carried
out repeatedly by the CPU.
(6 marks)
10. Consider the following problem: a man wishes to ferry a wolf, a
sheep and a bale of hay across a river. His boat will only hold one item at
a time. The wolf cannot be left with the sheep and the sheep cannot be
left with the hay. How can he ferry the three items?
The state of the man is represented by a bit. The bit is 0 if the man is on
the near side (original side) of the river and 1 if the man is on the far side
(final side) of the river. The states of the wolf, the sheep and the hay are
represented in the same way. The four bits are concatenated. For
example, if the state is 0011 then the man and the wolf are on the near
side of the river and the sheep and the hay are on the far side of the river.
a) What is the original or first state? What is the desired final state?
(2 marks)
b) Suppose that the current state is 0001. Describe in words the locations
of the participants.
(2 marks)
c) List all the states, both allowed and forbidden, that can follow from
0001 after one crossing of the river. Explain your answer.
(4 marks)
d) List all the allowed states that can follow from 0001 after one crossing
of the river.
(2 marks)
(End of the question paper)
COPYRIGHT:
OFFICIAL COURSE NUMBER:
Page numbering:
©Birkbeck College 2013
BUCI008H4
10 of 10
Download