First Semester Examination 2013 Introduction to Computer Systems (COMP2300/COMP6300 Paper A) Writing Period: 3 hour duration Study Period: 15 minutes duration Permitted Materials: One A4 page with notes on both sides. The rPeANUt specification will be made available. Note also the standard lab tools are available including: Java, eclipse, kate, dia, gcc, man, rPeANUt ... NO calculator permitted. Please Read The Following Instructions Carefully. This exam will be marked out of 100 and consists of 4 questions. Questions are of unequal value. The value of each question is shown in square brackets. Questions that are partitioned into parts show the number of marks given to each part within square brackets. Students should attempt all questions. Answers must be saved into the question's directory (Q1, Q2, Q3, Q4) using the file(s) described in the question statement. Marks may be lost for giving information that is irrelevant. Network traffic may be monitored for inappropriate communications between students, or attempts to gain access to the Internet. The marking scheme will put a high value on clarity so, as a general guide, it is better to give fewer answers in a clear manner than to outline a greater number (in a sketchy, half-answered fashion) of less clear answers. Page 1 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012 Question 1 [40 marks] Highest marks are gained by providing: clear, concise, and short answers. Save your answers in the text file 'Q1Answers.txt' in the directory Q1. This file can be edited using 'gedit'. Please make certain that this file is saved both as you progress through the exam and before the exam ends. i. [4 marks] How many different values can be stored in a 4 bit word? What is the range of numbers that is stored in a 4 bit word when two's complement representation is used? Convert the hexadecimal number 0xA to octal. What decimal number would the hexadecimal number 0xA represent if it was interpreted as a 4 bit two's complement number. ii. [4 marks] The IEEE 754 32-bit single-precision floating-point standard is: 1 bit sign, 8 bits exponent with a bias of 127 (normalized numbers), and the remaining 23 bits are the significand (mantissa). What decimal number does the float 0xC1F20000 represent? In this IEEE 32-bit floating-point standard what is the smallest number representable that is greater than zero (give your answer either as an expression or just the decimal number using scientific notation)? iii. [4 marks] Why do modern processors use more power when their clock frequency is increased? iv. [4 marks] How many bytes are there in a Megabyte (MB)? How does this value depend on the context in which the term Megabyte is used? How many bytes are there in a Mebibyte (MiB)? v. [4 marks] What is a process? What is the relationship between: a processor, a process, a program, and an algorithm? vi. [4 marks] What does an assembler do? What is involved in assembling a single instruction? vii. [4 marks] What does a cache write policy determine? State and explain the two basic cache write policies. viii.[4 marks] What CPU scheduling approach minimises the average wait time? Why is this scheduler generally impossible to implement? How may this scheduler be approximated? ix. [4 marks] What is multilevel paging? What issues or problem does multilevel paging overcome that a single level paging approach has? x. [4 marks] How is the stack used for the implementation of function calls within assembly or C programs? Page 2 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012 Question 2 [20 marks] (a) [5 marks] Write a program in rPeANUt that executes for exactly 100 instructions and then halts. If you run your program from the command line with the “-count” option it should output “Count : 100”. Also if you ran it within the GUI simulator then the “Count” should be 100 once the program has halted. Place your answer in a file called 'hundred.s' in the Q2 directory. Note this program doesn't need to do anything else but run for this fixed number of instructions. (b) [5 marks] Disassemble the program given in the image below. Place your answer in a file called 'disassemble.s' in the Q2 directory. Note your disassembled program should be able to be assembled by the rPeANUt assembler to the exact program in the image without any errors. Also exactly what will the program do when it is run (answer this question as a comment within the source of the disassembled program)? Page 3 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012 (c) [10 marks] The C code below implements a simple linked list that adds integers to a list and prints the sum of the list. This code, except the 'sum' function, has been converted to rPeANUt assembler code within the 'listsum.s' file in the Q2 directory. Add rPeANUt assembler code to the end of the 'listsum.s' file to implement the 'sum' function. Your solution must not modify the rest of the assembler code within 'listsum.s'. #include#include struct node { int value; struct node *next; }; struct node *list; void add(struct node **l, int v) { struct node *nnode; nnode = (struct node *) malloc(sizeof(struct node)); nnode->value = v; nnode->next = *l; *l = nnode; } int sum(struct node *l){ if (l == NULL) { return 0; } else { return sum(l->next) + l->value; } } int main() { list = NULL; printf("%d\n",sum(list)); add(&list, 7); add(&list, 3); printf("%d\n",sum(list)); add(&list, 6); printf("%d\n",sum(list)); return 0; } Page 4 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012 Question 3 [20 marks] (a) [5 marks] Write a C program that prints to standard output “Hello World!” on a single line (so you need to add a newline character to the end of the string). Place your answer in the file called 'hello.c' in the Q3 directory. (b) [5 marks] Write a C program that takes a single file name as a parameter and outputs to standard output the size of the file in bytes. You may assume the file exists and it is just a regular file. Place your answer in the file called 'mysize.c' in the Q3 directory. (hint - “man 2 stat”) (c) [10 marks] Write a program in C that converts binary numbers into hexadecimal numbers (only required to work on positive numbers). The binary numbers are provided to the program via standard input and are at most 16 bits long. Each binary line is separated via a return character. Place your answer in the file called 'bin2hex.c' in the Q3 directory. An example of the program running is given below (input typed by the user is given in bold): $ ./bin2hex 1111111111111111 0xFFFF 0000000000000000 0x0 0 0x0 10 0x2 1010 0xA 11110000 0xF0 101001011111 0xA5F 01010 0xA 111 0x7 Page 5 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012 Question 4 [20 marks] “Romanish numerals” are a simplified version of “Roman numerals” (I have just made them up for this exam question). “Romanish numerals” only have 2 symbols which are: 'X' which represents 10s, and 'I' which represents 1s. Romanish numerals are only integers that are 1 and above. The following list gives the decimal interpretation of the first 21 Romanish numerals: I is 1, II is 2, III is 3, IIII is 4, IIIII is 5, IIIIX is 6, IIIX is 7, IIX is 8, IX is 9, X is 10, XI is 11, XII is 12, XIII is 13, XIIII is 14, XIIIII is 15, IIIIXX is 16, IIIXX is 17, IIXX is 18, IXX is 19, XX is 20, XX1 is 21, …. Basically 'I's before the 'X's subtracts from the value, whereas 'I's after the 'X's add to the value. You can have at most 4 'I's before the 'X's, also you can have at most 5 'I' after the 'X's. The 'I's will either be: all before the 'X's, all after the 'X's, or just on their own (for numbers 5 and under). (a) [5 marks] Write a C program that takes a decimal number as a parameter and prints to standard output the “Romanish numeral” of that number on a single line, you may assume the decimal number given as a parameter ranges between 1 and 1000. Put your answer is a file called “printromanish.c” in the Q4 directory. (b) [10 marks] Write a program in rPeANUt that takes a single Romanish numeral ended by a new line character from the terminal and outputs the decimal value for that Romanish numeral and then halts. Put your answer in the “inputromanish.s” file in the Q4 directory (note you should be able to pipe the output of part (a) into the input for part (b) and end up with the number you gave part (a) as a parameter). Hint – you may make use of the code in 'listsum.s' from question 2(c) for printing decimals. (c) [5 marks] Construct an analytical model of the performance of the part of your rPeANUt program that parses the Romanish numerals (Basically work out the formula of how many instruction your program would execute to input the number into a register for different valued inputs). Discuss and compare this with the parsing of normal decimal numbers. Put your answer in a comment at the top of the “inputromanish.s” file in the Q4 directory. Page 6 of 6 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012