计算机架构代写 | CO883 Credit Retrieval Coursework

这个作业是设计一个旨在支持递归过程调用的CPU
CO883 Credit Retrieval Coursework

4. You are designing a CPU intended to support recursive procedure calls.
(a) Suggest names and brief descriptions of a pair of instructions which would allow this.
[Many correct answers are possible.] [4 marks]
(b) Given the need to support recursive procedure calls, name and briefly explain one feature
which you would include in the CPU’s register file. [2 marks]
(c) In the same way, name and briefly explain one area of memory you would expect to find
within a program running on this CPU. [2 marks]
5. You are looking at a block diagram of a processor design, and notice a data path from memory
into a register labelled ‘instruction register’.
(a) What does this register hold? [2 marks]
(b) What is the function of the circuits to which its outputs are connected? [3 marks]
(c) Would you expect to find this register described in the instruction set manual? Explain
your answer briefly. [2 marks]
2
6. You are working with an unfamiliar 32-bit processor and have been given the following assembly
code, whose purpose is to compute the length of a character string. The string is terminated by a
zero (NUL) byte.
mov #0x0,%r1 ; set r1 to 0
loop:
cmpb #0x0,(%r2) ; load 1 byte from memory and compare with 0x0
je out ; jump if compared true
add #0x1,%r1 ; add 1 to r1
add #0x1,%r2 ; add 1 to r2
jmp loop ; jump to loop
out:
nop ; do nothing
(a) When the code has finished executing, which register holds the length of the string? [1 mark]
(b) A colleague tells you that the routine works only for one particular character encoding,
but they can’t remember whether that is ASCII or UTF-8. Which is it, and how did you
deduce that? [3 marks]
(c) Suppose you had to provide a routine for the other character set (i.e. either UTF-8 or
ASCII, depending on your answer above). Briefly, what is the principal change that would
be needed to the code above? [3 marks]
7. This question is about binary arithmetic and number representation.
(a) Draw a circular diagram representing the values of a 3-bit two’s complement number
representation. Label it clearly, including decimal and binary representations at each
position. [4 marks]
(b) State and explain two advantages of two’s complement over a sign/magnitude encoding. [4 marks]
(c) Explain what is meant by ‘floating-point representation’, giving an example. [5 marks]
(d) You have a computer whose ALU provides only integer arithmetic, with no support for
floating-point operations. You wish to write a program that involves numbers with a
fractional part. Identify two approaches to working with such numbers and, explain some
of the factors that would allow you to decide between them. [5 marks]
(e) You are given some code that uses a 16-bit floating-point representation to provide trigonometric functions (such as sin and cos) using a look-up table. You need to port this to a
32-bit floating-point representation. Explain why this is likely to require an entirely new
approach to implementing the functions. [Hint: if you are not familiar, you may have to
look up ‘look-up table’ in a textbook or online resource.] [4 marks]
3
B Operating Systems
Answer each of the following questions in about 500 words. Feel free to use drawings, sketches, code,
equations, and so on, as appropriate.
8. Describe the main components of an operating system and their functions. [5 marks]
9. Which parts of the virtual memory are implemented in software and which are implemented in
hardware? [5 marks]
10. Describe how a thread pool should be used in Java. Make sure to include at least one example. [5 marks]
11. Describe how a condition variable should be used in multithreaded programming. Make sure
you include at least one example. [5 marks]
12. Describe the buddy system memory allocation system. Make sure you include at least one
example. [5 marks]
13. Describe how the mark&sweep garbage collecting algorithm works. Make sure to illustrate at
with at least one drawing of the heap. [5 marks]
Answer each of the following questions by giving one or more bash commands, followed by a short
explanation of how they work.
14. File marks.txt contains data in the following format:
rg399 14
sk45 93
The first column is a student identifier; the second column is an exam mark. Compute the
average mark. [2 marks]
15. Using the same file as in the previous question, compute what percentage of students passed. A
student is deemed to have passed if the mark is at least 50. [2 marks]
16. Using the same file as in the previous two questions, sort students (and their marks) from highest
to lowest mark. [2 marks]
17. The file all_marks.txt contains data in the following format:
rg399 51 50 67
pl892 33 100 89