Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
First Semester Examination 2013
Introduction to Computer Systems
(COMP2300/COMP6300 Paper B)
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, the  
calculator on the computer,  ... 
NO calculator permitted (physical electronic device). 
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 of less 
clear answers. 
Page 1 of 7 - 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 (note this file is already 
created with the below questions added, so just open up 'Q1Answers.txt' and save 
your answers directly into it).  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] What is the difference between DRAM and static RAM in terms of: 
the components used to construct them, capacity,  speed, and latency? 
iv. [4 marks] What is a system call?  Why are they important for modern operating 
systems?  How are system calls implemented in Linux based x86 machines?
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] Suppose you have a 4-way set associative cache which has in total 
4096 bytes of cache memory and each cache line is 128 bytes.  How many 
sets are there is this cache?  If memory is byte addressable and addresses 
are 16 bits then how many bytes are used for the tag?   
viii.[4 marks] Suppose 4 processors are currently waiting on the ready queue of a 
single threaded CPU.   If the CPU becomes available to schedule these 
processes and the burst times of the 4 processes are 10ms, 100ms, 40ms, 
and 10ms (also arriving on the ready queue in that order).  What is the 
average wait time if a FCFS scheduler is used?  How does this compare the 
SJF scheduling approach?
ix. [4 marks]  What is the relationship between IP, UDP, and TCP?
x. [4 marks] In Linux what is a file descriptor?  In Linux what are the two available 
approaches for reading the contents of that file (assuming you have a file 
descriptor of an open file)?  List some situations when you would use one 
approach over the other approach.
Page 2 of 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012
Question 2 [20 marks]
To run rPeANUt open up a terminal and run the following:
% cd
% java -jar rPeANUt2.3.jar
(a) [5 marks] Write a program in rPeANUt that prints “Hello World!” to the terminal.   
Place your answer in a file called 'hello.s' in the Q2 directory. (Hint you do not need to 
use a loop.) 
(b) [5 marks] Disassemble the program given in the image below.   Place your 
answer in a file called 'disassemble.s' in the Q2 directory.  To get you started I have 
disassembled the first part of the program.  Note your disassembled program should 
be able to be assembled by the rPeANUt assembler to the exact program in the 
image without any errors (note I have included the file "disassemble.objdump" which 
was produced by the -objdump option, so one way of checking your solution is to 'diff' 
this file with the objdump of your disassembled code).     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 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012
(c) [10 marks] The C code below calculates the greatest common divisor (gcd) of a 
series of pairs of numbers.   Convert this C code into rPeANUt assembler code.   
Your solution must implement a procedure for 'gcd' using the recursive approach 
given below.  Also, use the conventional rPeANUt stack frame approach for this 
procedure.    Note within 'gcd.s'  you are given some code that will print out the 
decimal numbers to the terminal.   Place your answer in a file called 'gcd.s' in the Q2 
directory. 
#include  
int gcd(int m, int n) {
   if(m == n)
      return m;
   else if (m > n)
      return gcd(m-n, n);
   else
      return gcd(m, n-m);
}
void main() {
    printf(“%d\n”, gcd(6,15)); // prints 3
    printf(“%d\n”, gcd(6,4)); // prints 2
    printf(“%d\n”, gcd(30,84));  // prints 6
} 
Page 4 of 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012
Question 3 [20 marks]
(a) [5 marks] Write a C program that outputs to standard out the numbers from 1 to 
10 with comma separation using a 'for' loop.  This list of numbers should be on a 
single line (put a newline character at the end of the line).  Place your answer in the 
file called  'count.c' in the Q3 directory.  When run from the command line you should 
see:   
$ ./count
1,2,3,4,5,6,7,8,9,10
$ 
(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”)  When run from the command line you should see :
$ ./mysize 100bytefile
100
$ ./mysize emptyfile
0
(c) [10 marks] Write a program in C that is given a list of numbers via standard input 
(each number is space separated and all the input are on a single line)  and finds the 
maximum number in the list and prints it on a single line to standard output.  If the list 
is empty then it just prints "empty".   Below are some examples of running the 
program on the command line (echo and a pipe are a simple way of directing input to 
the program).  Place your answer in the file called  'max.c' in the Q3 directory.
$ echo "2 3 7 3 5" | ./max
7
$ echo "" | ./max
empty
$ echo "4" | ./max
4
$ echo "4 2 9" | ./max
9
$ echo "14 2 9" | ./max
14
$ echo "-14 -2 -9" | ./max
-2
Page 5 of 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012
Question 4 [20 marks]
Strings in rPeANUt use an entire word for each character (along with a word for the 
null string terminator).  So if we are to assemble:
0x0300 : block #"Hello World!!" 
we would end up with 14 words used:
 
The good thing about this is a function for printing strings is short and simple. e.g.
; void printstr(char *str) // SP #-1 is the address of the string
printstr :  load SP #-1 R1
psloop:     load R1 R2
            jumpz R2 psexit
            store R2 0xfff0
            add R1 ONE R1
            jump psloop
psexit:     return
However, assuming we are only considering ASCII character encodings, we end up 
wasting approximately ¾ of the memory.   One alternative would be to pack 4 
characters into 1 word (assume a little endian ordering), with the null terminator also 
only taking 1 byte.  So now we can represent the same string in 4 words by using the 
assembly code:
0x0300 :  block #0x6c6c6548  ; "Hell"
          block #0x6f57206f  ; "o Wo"
          block #0x21646c72  ; "rld!"
          block #0x00000021  ; "!" with a null byte
So although we save space in representing the string we will use more space for the 
function that prints a string. 
Page 6 of 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012
(a) [7 marks] Write a C program that takes a string as a parameter and prints to 
standard output the rPeANUt assembly code that represent the packed copy of the 
code (as explained above).  You should be able to cut-and-paste the output of this 
program into an rPeANUt program you are writing.  If you ran your program from a 
terminal you would expect:
$ ./packstring 'Hello World!!' 
    block #0x6c6c6548 
    block #0x6f57206f 
    block #0x21646c72 
    block #0x00000021 
 Put your answer is a file called “packstring.c” in the Q4 directory.   
(b) [7 marks] Add rPeANUt assembler code to the end of the 'printstring.s' file in the 
Q4 directory to implement the 'printstrpacked' function.   The 'printstrpacked' function 
prints to the terminal the string given to it as a parameter.  The parameter is just a 
pointer to the string to be printed.   Your solution must not modify the rest of the 
assembler code within 'printstring.s'.
    
(c) [6 marks] Construct an analytical model of the space used by the packed 
approach for different sized strings (this is just a formula for how much memory it 
takes to represent a string along with the amount of memory it takes to implement the 
printstrpacked  function).  Do this analysis also for the basic string approach.   At 
what point does it become more space efficient to use the packed string approach as 
opposed to the basic approach?   How do the 2 approaches compare in terms of time 
performance?   Put your answer in a comment at the bottom of the “printstring.s” file 
in the Q4 directory.  
Page 7 of 7 - Introduction to Computer Systems - (COMP2300/COMP6300) 2012