Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Birkbeck (University of London) BSc/FD EXAMINATION Department of Computer Science and Information Systems Introduction to Computer Systems (BUCI008H4) CREDIT VALUE: 15 credits Summer 2016 Examination SUMMARY ANSWERS Date of examination: Thursday 2nd June 2016 Duration of paper: 14.30 – 16.30 This paper is split into Section A and Section B. There are ten questions in this paper. Answer all ten questions. Each question carries 10 marks in total. Calculators and other electronic devices are not permitted. The examination is closed book. No supplementary material is provided. This paper is not prior disclosed. BUCI008H4 Page 1 of 8 c ⃝Birkbeck College 2016 Section A: Number Representations and Boolean Operations (40 marks) 1. 2. Show your working in all parts of this question. (a) Add the binary numbers 10010 and 1011. (2 marks) Answer: 11101. Two marks. One mark for the correct answer without any working. (b) Subtract the binary number 1011 from the binary number 10011. (2 marks) Answer: 1000. Two marks. One mark for the correct answer without any working. (c) Multiply 210 , i.e. two to the power ten, and 213 , i.e. two to the power thirteen. An answer in the form of a power of two is required. (2 marks) 23 Answer: 2 . Two marks. One mark for the correct answer without any working such as 23 = 10 + 13. (d) Convert the binary number 10110 to the corresponding decimal number. (2 marks) Answer: 22. Two marks. One mark for the correct answer without any working. (e) Convert the hexadecimal numbers A and B to the corresponding decimal numbers, add the decimal numbers and convert the result to hexadecimal form. (2 marks) Answer: A is decimal 10 and B is decimal 11. Add to obtain decimal 21, which is hexadecimal 15. Two marks Show your working in all parts of this question. (a) Write out the table for the three bit excess notation for integers. Show clearly the integers which can be represented using the three bit excess notation. (4 marks) Answer: 4 marks. 1/2 mark for each correct entry in the following table. 3 111 2 110 1 101 0 100 -1 011 -2 010 -3 001 -4 000 (b) Obtain the four bit two’s complement representations for the integers -1 and 2. Obtain from these two’s complement representations the two’s complement representation for the integer 1. Note that -1+2 is equal to 1. (4 marks) Answer: 1111 and 0010. On adding these bit strings as if they are binary numbers the bit string 10001 is obtained. The rightmost 4 bits of 10001 are the two’s complement representation for 1. 4 marks. One mark for each correct two’s complement representation of -1, 2 and 1. One mark for a correct addition. BUCI008H4 Page 2 of 8 c ⃝Birkbeck College 2016 3. (c) Find two integers m, n with corresponding three bit excess representations s, t, such that i) m + n has a three bit excess representation u; and ii) u is not equal to the rightmost three bits of the bit string obtained by adding s and t as if they were binary numbers. (2 marks) Answer: Two marks for any correct answer, e.g. m = 0, n = 1. (a) State the name of one binary Boolean operation. Explain the meaning of the word binary in this context. (4 marks) Answer: Two marks for naming any binary Boolean operation such as AND, OR, Exclusive OR, etc. A truth table is not required. Two marks for stating that the term binary indicates that the Boolean operation acts on pairs of values. Four marks in total. (b) Write out the truth table for the Boolean operation A == B. If A and B have the same value, then A == B is true (1 or T is also accepted), otherwise A == B is false (0 or F is also accepted). (4 marks) Answer: One mark for each correct row, making four marks in total. A B A == B 0 0 1 0 1 0 1 0 0 1 1 1 Describe one way in which Boolean operations are used in programming languages. (2 marks) Boolean operations are used to make decisions about the flow of control in a program. Two marks. Two marks if the answer consists of a reasonable example. Relational operators such as < are not counted as Boolean operators. (c) 4. The Brookshear floating point representation for a binary fraction x consists of eight bits, labeled s, e1 , e2 , e3 , m1 , m2 , m3 , m4 from left to right. If x is zero, then all eight bits are zero. If x is strictly negative, then the sign bit s is 1. If x is strictly positive, then the bit s is zero. Next, suppose x is not zero. To obtain the remaining seven bits, x is written in the form ±2r ∗ 0.t where r is an integer and t is a bit string such that the leftmost bit of t is 1. The bits e1 , e2 , e3 together comprise the three bit excess notation for r and the bits m1 , m2 , m3 , m4 of the mantissa are the leftmost four bits of t. (a) Obtain the Brookshear floating point representation for the decimal fraction 1/16. In your answer show the value of r and the value of the bit string 0.t. (8 marks) Answer: 00011000 (four marks), r = −3 (two marks) and 0.t = 0.1000 (two marks), making eight marks in total. BUCI008H4 Page 3 of 8 c ⃝Birkbeck College 2016 (b) Suppose that the Brookshear floating point representation for a non-zero number x is given. Explain how it is possible to obtain quickly the Brookshear floating point representation for the number 2x, under the assumption that the representation of 2x exists. (2 marks) Answer: Increase the exponent by 1. Two marks. One mark for an example without any statement of the general method. Section B: Programming and Structure of a Computer (60 marks) 5. The table included below in this question describes instructions of length 16 bits, made by concatenating an op-code and an operand. The first four bits record the op-code. The remaining 12 bits record the operand. Four bits are required to specify a register R and eight bits are required to specify a memory location XY . Each register holds eight bits and each memory location holds eight bits. 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. Op code 1 2 3 4 5 Operand RXY RXY RXY 0RS RST 6 RST 7 RST 8 RST 9 RST A B R0X RXY C 000 BUCI008H4 Description Load register R with the bit pattern in memory cell XY . Load register R with the bit pattern XY . Store the bit pattern in register R at memory cell XY . Move the bit pattern in register R to register S. Add (two’s complement) the bit patterns in registers R and S. Put the result in register T . Add (floating point) the bit patterns in registers R and S. Put the result in register T . Or the bit patterns in registers S and T . Put the result in register R. And the bit patterns in registers S and T . Put the result in register R. Exclusive Or the bit patterns in registers S and T . Put the result in register R. Rotate the bit pattern in register R one bit to the right X times. Jump to the instruction in memory cell XY if the bit pattern in register R is equal to the bit pattern in register 0. Halt. Page 4 of 8 c ⃝Birkbeck College 2016 6. (a) Describe the result of the instruction 9312 when register 1 contains A6 (in binary 10100110) and register 2 contains F F (in binary 11111111). (4 marks) Register 3 contains the bit string 01011001. Four marks. Two marks for stating that the result appears in register 3 and two marks for the correct bit string. One mark if it is stated that the bits in register 1 are flipped without any further answer. (b) Write a program in machine code to i) read the contents of the memory cell with the hexadecimal address 91 into register 1; then ii) flip the bits of the bit string in register 1 and put the resulting bit string in register 3; and finally iii) copy the bit string in register 3 to the memory cell with address 91. The bits in a bit string are flipped by converting 0 to 1 and 1 to 0. For example, if the bit string is 00110011, then flipping the bits yields the bit string 11001100. (6 marks) Answer: 1191 22FF 9312 3391 Six marks. Any reasonable answer accepted, including 1191, 9312, 3391 in which it is assumed that register 2 already contains FF. Two marks deducted for each mistake. (a) Give a definition of the term algorithm. Give a definition of the term variable, as this term might be used when describing an algorithm. (4 marks) Answer: An algorithm is an ordered sequence of unambiguous executable steps that defines a terminating process. Two marks. Two marks for any reasonable variation in this wording. For example, an algorithm is a finite sequence of executable instructions. A variable is a named memory location or a variable is a quantity that has a name and a value. Either answer is accepted. Two marks. (b) State one advantage in using a high level programming language to implement algorithms. (2 marks) Answer: An algorithm can be programmed using fewer instructions than would be required in a machine code version of the same algorithm. Two marks. Any reasonable answer accepted. (c) Consider the following statement. To convert degrees centigrade into degrees Fahrenheit, multiply by 9/5 and add 32. This statement is to be the basis for an algorithm. Identify the input and the output of the algorithm. Suggest two variables that might be used in an implementation of this algorithm. (4 marks) Answer: The input is a number of degrees centigrade. The output is the corresponding number of degrees Fahrenheit. The two variables could be the number c of degrees centigrade and the number f of degrees Fahrenheit. Four marks. One mark for each item. BUCI008H4 Page 5 of 8 c ⃝Birkbeck College 2016 7. Recall that an array is a block of values of the same type, for example, ( A= 1 2 0 9 4 6 ) The indexing of the rows and columns of an array starts in each case from 0 and the index for the rows is given first. For example, A[0, 1] has the value 2. 8. (a) Describe one way in which the array A might be stored in a computer memory. Use a diagram to show clearly where the different values in A are placed. You may assume that each entry of A is stored in a single memory cell. (4 marks) Answer: row major order is assumed in this answer but other arrangements, e.g. column major order, are accepted. The rows of A are placed in memory side by side. Four marks. Full marks given for a diagram. 1 2 4 0 9 6 (b) If the memory cell for the value 1 is x then what is the memory cell for the value 9? (2 marks) Answer: x + 4. Two marks (c) Let x be the memory cell in which A[0, 0] is stored. Show how the location of the memory cell holding A[i, j] can be calculated using the values of x, i and j. (4 marks) Answer: x + 3i + j. Four marks. (a) Define the term pointer. Answer: a pointer is a storage area containing an address. Two marks. (b) Draw a diagram to show a linked list in a computer memory. The list must contain three elements. Each element consists of data and a pointer. Assume that the three data items are A, B, C and that each item occupies a single memory cell. In addition, assume that for each element the pointer is the memory cell immediately following the memory cell for the data. Explain the significance of the head pointer and the nil pointer. (6 marks) Answer: Four marks for any reasonable diagram, for example, cell contents A 8 C nil B 6 cell address 1 2 3 4 5 6 7 8 9 10 The head pointer points to the address of the first item on the list. In this case the head points has the value 3. One mark. The nil pointer marks the item at the end of the list. One mark. BUCI008H4 Page 6 of 8 (2 marks) c ⃝Birkbeck College 2016 (c) Use pseudo code to describe an algorithm that takes as input the head pointer of a list and prints out the data in each element of the list. (2 marks) Answer: Any reasonable answer accepted for two marks, for example 1. 2. 3. 4. 5. 9. p = head pointer while(p != nil) print(p.data) p = p.next endWhile Consider the following pseudo code for a recursive function that computes the factorial function. 1. function f act(n) 2. if(n == 0) 3. return 1 else 4. return n ∗ f act(n − 1) 5. 6. endFunction (a) Show in detail how the integer f act(3) is calculated. (4 marks) Answer: When f act(3) is called n has the value 3. It follows that the quantity 3 ∗ f act(2) is returned. In the function call f act(2), n has the value 2. It follows that the quantity 2 ∗ f act(1) is returned. Thus the call f act(3) returns 3 ∗ 2 ∗ f act(1). The call f act(1) returns 1 ∗ f act(0) which reduces to 1. It follows that f act(3) returns 3*2*1 which is 6. Four marks. (b) Which feature in the pseudo code for f act ensures that the function is recursive. (4 marks) Answer: The feature is in line 5. The function fact calls itself, but with a smaller value for the argument. Four marks. (c) What happens if the function call f act(−1) is attempted? (2 marks) Answer: the function f act calls itself and indefinitely large number of times. No value is returned. On any ”real” system the final result will be some kind of error. Two marks. BUCI008H4 Page 7 of 8 c ⃝Birkbeck College 2016 10. Consider the following pseudo code for the function compare. The two arguments a, b of compare are arrays. The array indexing begins at 0. The notation ! = means not equal to. 1. function compare(a, b) : 2. if(length(a) ! = length(b)) return F alse 3. i=0 4. while(i < length(a)) 5. if(a[i] ! = b[i]) return F alse 6. i=i+1 7. endWhile 8. return T rue 9. endFunction (a) What value is returned by compare if a = {1, 2, 3} and b = {1, 2, 4}. It is not necessary to show the detailed steps of the pseudo code, but it is necessary to justify your answer. (4 marks) Answer: The function compare returns F alse because a and b differ in the last entry. Four marks. (b) What value is returned by compare if a and b are both of length 0? Answer: True. Two marks. (c) Rewrite the pseudo code for compare in order to produce a new algorithm compare2 that returns T rue if a is equal to b in reverse order, and returns F alse otherwise. For example, compare2 returns T rue if a = {1, 2, 3} and b = {3, 2, 1}. (4 marks) Answer: Four marks for any reasonable attempt with one mark deducted for each significant error. One example of compare2 is as follows. 1. 2. 3. 4. 5. 6. 7. 8. 9. BUCI008H4 (2 marks) function compare2(a, b) : if(length(a) ! = length(b)) return F alse i=0 while(i < length(a)) if(a[i] ! = b[length(b) − i − 1]) return F alse i=i+1 endWhile return T rue endFunction Page 8 of 8 c ⃝Birkbeck College 2016