BIRKBECK (University of London) BSc/FD Examination for Internal Students Department of Computer Science and Information Systems Introduction to Computer Systems SUMMARY ANSWERS (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 11 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) Answer: 10110. One mark for the correct answer with no working. b) Multiply the two binary numbers 1101 and 11. Show the result in binary form. (2 marks) Answer: 100111. One mark for the correct answer with no working. c) Convert the following two binary numbers into hexadecimal numbers: 11101010 and 111010. (2 marks) Answer: EA and 3A. One mark for the correct answers with no working. d) Express the following two decimal numbers in three bit excess notation: 3 and -2. (2 marks) Answer: 111 and 010. One mark for the correct answers with no working. e) Add the following two hexadecimal numbers: 7 and 8. Show the result in hexadecimal form. (2 marks) Answer: F. One mark for the correct answer with no working. 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) Answer: yes, yes, no, yes. ½ mark for each correct answer. 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 COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 2 of 11 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) Answer: 01111110. Two marks for the correct answer with no working. ii) Obtain the decimal number that has the Brookshear floating point representation 01101010. Show your working. (3 marks) Answer: 2+(1/2). Two marks for the correct answer with no working. 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) Answer: 7+(1/2). One mark for the correct answer with no explanation. 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) Answer: A AND B, A XOR B, NOT(A), NOT(A OR B). One mark for each correct item. COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 3 of 11 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) Answer: NOT(A AND NOT B). The expression A AND NOT(B) has the value 1 if and only if A = 1 and B = 0. It follows that NOT(A AND NOT(B)) has the value 0 if and only if and only if A = 1 and B = 0. Thus it matches the truth table for A IMPLIES B. One mark for the correct answer with no explanation. 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) Answer: 1 (True). One mark for the correct answer with no working. ii) (NOT(A) OR NOT(C)) AND B (2 marks) Answer: 1 (True). One mark for the correct answer with no working. 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) Answer: False, True, False, True. One mark each. (4 marks) COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 4 of 11 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) Answer: A1 A2 C 0 0 0 0 1 0 1 0 0 1 1 1 11+1=100. To obtain the right most bit use the table for B with A1=1 and A2=1, to obtain right most bit = 0. To obtain the right most carry use the table for C with A1=1 and A2=1, to obtain 1. Add the right most carry and the left most bit of 11 in the same way to obtain 0 carry 1. The 0 is the next bit of the answer and this second carry is then the left most bit of the answer. Two marks for the table and 4 marks for the explanation. 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) Answers: 1011, 101010. One mark for the correct answers with no working. b) Convert the following two binary integers to decimal integers: 11, 1101. (2 marks) Answers: 3, 13. One mark for the correct answer with no working. 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}. COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 5 of 11 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) Answer: Test to see if m equals 0. The test returns False. Initialise b with the empty list {}. Test to see if m is strictly greater than 0. The test returns True. Enter the while loop. Divide m by 2 to obtain quotient q = 1 and remainder r = 1. Prepend r to b to obtain b = {1}. Assign the value 1 of q to m. Test to see if m is strictly greater than 0. The test returns True. Enter the while loop. Divide m by 2 to obtain quotient q = 0 and remainder r = 1. Prepend r to b to obtain b = {1, 1}. Assign the value 0 of q to m. Test to see if m is strictly greater than 0. The Test returns False. Exit the while loop, output b and halt. 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) Answer: replace the lines within the while loop with 4. Divide m by 16 to give quotient q and remainder r 5. Convert r to the appropriate hexadecimal integer h 6. m = q; 7. b = Prepend[r, b]; 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. COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 6 of 11 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. 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 COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 7 of 11 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) Answer 25C0 3592 2500 load the bit pattern 00 in register 5 3593 store the contents of register 5 at memory cell 93 2101 load the bit pattern 01 in register 1 1290 load the contents of memory cell 90 in register 2 1091 load the contents of memory cell 91 in register 0 B292 Jump to the instruction stored at memory cells 92 and 93 if register 2 and register 0 have the same contents. 2100 load register 1 with bit pattern 00 C000 halt ½ mark for each correct line. 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 finds the list of instructions in part (a) of this question un-illuminating. (6 marks) Answer: The instruction C000 for Halt is stored in memory cells 92 and 93. The bit pattern 01 is loaded into register 1. The two numbers to be compared are loaded into registers 2 and 0 respectively. The contents of registers 2 and 0 are compared. If the contents are equal then the value in register 1 is correct and the next instruction to be carried out is C000 (Halt). If the contents are not equal, then 00 is loaded into register 1 and the program halts. 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) COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 8 of 11 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) Answer: A bit string specifies a set of powers of 2 in the following way. A 1 in the nth place, reading from the left, corresponds to the power 2^(n1). A 0 in the nth place indicates that the power 2^(n-1) is absent. The sum of the powers of 2 associated with a bit string yields the integer represented by the bit string. In the case of the number 7 the bit string is 111, which specifies 2^(0), 2^(1) and 2^(2), on reading the bit string from right to left. The sum of these powers of 2 is equal to 7 thus 7 is represented by 111. Four marks for any reasonable answer. Two marks for a good illustration of the answer using the integer 7. 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) Answer 1. Input n; 2. k = 0; 3. While (2^(k) <= n) 4. k = k+1; 5. EndWhile; 6. Output k-1; Four marks for any reasonable version. No marks if there is no while loop. 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) Answer: k is the greatest integer such that 2^(k)<=n and the least integer such that 2^(k+1)>=n. Suppose that n has a binary representation with r bits. It follows that 2^(r) > n, thus r >= k+1. The smallest number with r bits is 2^(r-1) thus 2^(r-1) <= n and hence r-1<=k. It follows that r = k+1. One mark for the correct answer with no supporting argument. COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 9 of 11 8. (a) Define a pointer. (2 marks) Answer: a pointer is a storage area containing the address at which a piece of information is stored. (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) Answer: if items are to be stored side by side by side then the gap left by any deleted item must be filled by moving the remaining items in memory. This could take a lot of time, especially if the items are large. (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) Answer: a pointer is associated with each item. The items are stored at any convenient locations in memory. The pointer associated with a given item is initialised with the address of the next item in the list. The pointer associated with the last item has a special null value. The location of the first item is indicated by a head pointer associated with the list as a whole. Two marks for the description, two marks for a reasonable diagram. (d) Describe the process of deleting the first item from your example of a linked list in part (c) of this question. (2 marks) Answer: The value of the head pointer is set equal to the position of the second item. 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) Answer: the diagram should show the control unit, the arithmetic and logic unit, the registers, the programme counter, the instruction register, the bus and the main memory, all labelled correctly. COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 10 of 11 b) Describe the machine cycle, i.e. the sequence of three actions carried out repeatedly by the CPU. (6 marks) Answer: the three actions are as follows. Fetch: load the instruction register with an instruction from the main memory using the address in the program counter. Update the program counter with the next memory location. Decode: find the op code of the instruction, and the actions specified by the instruction. Execute: carry out he instruction. Two marks for each action. 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) Answers: 0000, 1111. One mark each. b) Suppose that the current state is 0001. Describe in words the locations of the participants. (2 marks) Answers: the man, the wolf and the sheep are on the near side of the river. The hay is on the far side of the river. ½ mark for each correct location. 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) Answers: 1001, 1101, 1011. One mark each and one for the explanation. d) List all the allowed states that can follow from 0001 after one crossing of the river. (2 marks) Answers: 1101, 1011. One mark each. (End of the question paper) COPYRIGHT: OFFICIAL COURSE NUMBER: Page numbering: ©Birkbeck College 2013 BUCI008H4 11 of 11