COMP 00 00 final exam S 0

COMP / Final Exam

Student ID:

Reading time: minutes

Writing time: minutes

Makesure you readeachquestion carefully. Somewords have footnotes to clarifywhat they
mean in the context of the question.

Questions are not equally weighted, and the size of the answer box is not necessarily related
to the length of the expected answer or the number of marks given for the question.

All answers must be written in the boxes provided in this booklet. You will be provided with
scrap paper for working, but only the answers written in this booklet will be marked. Do not
remove this booklet from the examination room. There is additional space at the end of the
booklet in case the boxes provided are insufficient. If you use these extra pages, make sure
you clearly label which question the answer refers to.

Greatermarkswill be awarded for answers that are short and specific rather than long, vague,
or rambling. Marks may be deducted for providing information that is irrelevant to a ques-
tion. If a question ask for you to “explain your answer”, make sure both your answer (e.g.
yes/no) and your explanation are clearly indicated. If a question has several parts, you may
answer the later parts even if you cannot answer the earlier ones.

Where you are asked to write assembly code programs,marks will not be deducted forminor
syntax errors.

like this one!

For examiner use

COMP 00/ 00 final exam S 0

Question Logic, Bits, and Instructions ( marks total)

Part marks
Suppose the following code is executed. What will the final value of r0 be? Choose your an-
swer from the options below.

mov r0, 0b10101101
mov r1, 0b00011101
orr r0, r0, r1

• 0b10101111

• 0b11101101

• 0b11111111

• 0b10101101

Part marks

Using the T encoding for the lsr instruction as shown above, fill out (in the boxes provided)
the -bit bit pattern ( s and s) which represents the following line of assembly code:

lsr r1, r6

1415 1213 1011 89 67 45 23 01

COMP 00/ 00 final exam S 0

Part marks

What will the values of the NZCV status bits be after these instructions are executed? What
value will be in r0? Fill in your answers in the spaces below.

mov r0, 0xfffffff0
mov r1, 0x10
adds r0, r0, r1

Part marks

You want to implement a pseudo-instruction called not that will invert a register’s value in a
bit-wise manner. The pseudo instruction’s behaviour will be defined as follows:

not Rn, Rm @ Rn := ~Rm

What set of instructions could be used to implement not? Try to use the fewest instructions
possible, and note down if any extra registers, other than Rn and Rm mentioned above, are

COMP 00/ 00 final exam S 0

Part marks

You’re responsible for designing a new CPU that only uses only NOR gates (defined as fol-

Draw diagrams to define a circuit that is equivalent to a logical NOT gate using only NOR

Part marks
Drawdiagrams to define a circuit that is equivalent to a logical OR gate using onlyNORgates
(as defined above).

COMP 00/ 00 final exam S 0

Part marks

What are flip-flop circuits, and how could they be used as part of a CPU? Be as specific as you
can. You may include pictures/diagrams in your answer.

COMP 00/ 00 final exam S 0

Question Control Structures and Functions ( marks total)

Part . marks

Suppose a function f obeys the ARMArchitecture Procedure Call Standards (AAPCS). f takes
three parameters and returns one -bit value.

After f completes, in which of the following places will the return value be found?

• on the stack

• in the .data section

COMP 00/ 00 final exam S 0

Part . marks

Suppose the following assembly code has stored the values , , , and on the stack.

mov r3, #32
stmdb sp!, {r3}
mov r3, #7
stmdb sp!, {r3}
mov r3, #84
stmdb sp!, {r3}
mov r3, #128
stmdb sp!, {r3}

Which of the following instructions will load the value into r3?

• ldr r3, [sp]

• ldr r3, [sp, #4]

• ldr r3, [sp, #8]

• ldr r3, [sp, #12]

• ldr r3, [sp, #16]

COMP 00/ 00 final exam S 0

Part marks

Implement the following “for”-loop in ARMv assembly code.

int acc = 0;
for (int i = 0; i < 10; i = i+1) { acc = acc + i; COMP 00/ 00 final exam S 0 Part marks Write a recursive assembly function (starting at the label pow) which calculates the power pow(x, y) = xy ( ) for positive integers x and y. Add comments to explain how the parameters are passed into the function and where the result will be stored. For this question, you can assume that the result will fit into a -bit unsigned integer, so do not worry about numerical overflow in your function. COMP 00/ 00 final exam S 0 Part marks Theoutputof ourpow function is likely tooverflow, for instance,whencalculatingpow(2, 33). If youwere given the task of optimising the pow function to express numbers that are as large as possible what changes could you make? Explain your answer. Be as specific as you can. You may include pictures/diagrams in your answer. COMP 00/ 00 final exam S 0 Question Asynchronism&data ( marks total) Part marks Select the best definition of the term “mutual exclusion” below. • A method to save data in memory so that no process can modify it. • A method to ensure that only one program can access a shared resource at a time. • A method to determine whether two programs are accessing memory at once. • A method to exclude programs from accessing the private memory of other programs. • A method to stop multiple programs from changing CPU registers. • A method for saving data in between context switches. Part marks Of the program tasks below, select the three that are most likely to be accomplished with interrupts in a discoboard program. Your first three selections will be considered to be your • Turning on an LED. • Branching based on the value of a register. • Sending data over a network. • Receiving data over a network. • Calculating the frequency of a musical pitch. • Scheduling a regularly timed event. • Playing MIDI notes. • Loading data frommemory. • Setting peripheral control registers. • Responding to unexpected errors. COMP 00/ 00 final exam S 0 Part marks You’ve been asked to write a simple encryption program to obscure lower-case text data on a discoboard by shifting each letter one position backwards (e.g., “b” should be encoded as Theprogramshouldnotaffectpunctuation, spacesorupper-case letters. The letter “a” should be wrapped to “z”. Your first task is to write a function to apply this encryption scheme to a single lower-case letter stored inmemory. Write a function called encode_letter, that takes amemory location as its argument, loads and encodes the letter, and finally stores the encoded letter back in the same memory loca- You can assume that the character’s memory location is passed to your function in r0. You can use the ASCII encoding scheme below to assist you. Answer on the next page. COMP 00/ 00 final exam S 0 Write your answer for Part here: COMP 00/ 00 final exam S 0 Part marks Now use your encode_letter function to encode a string of characters inmemory. You can assume that the string is stored at the label string_location in the .data section and that it is zero-terminated as shown: Make sure your answer accounts for strings of different lengths. COMP 00/ 00 final exam S 0 Part marks Explain using diagrams and text what happens to a discoboard program before, during, and after handling an interrupt. Make sure to indicatewhat happens to the program’s execution process as it transitions from normal execution to the interrupt handler, and then back again. COMP 00/ 00 final exam S 0 Question Networks, OS,&Architecture ( marks total) Part marks You have been asked to build a traffic light controller for a -way intersection using dis- coboards. You’re responsible fordesigning thephysicalconnectionsbetween thediscoboards, and software to run on them. Each of the four traffic lights contains one discoboard and candisplay three signal lights (red, yellow, and green). A fifth discoboard (the control board) will be used as a remote controller for the four traffic light discoboards. The traffic light setup might look something like this: Your first task is to describe a protocol for the control discoboard to control the lights on just one traffic light board. Your protocol must be able to turn each signal colour on and off. Discuss the physical connections needed and whether your protocol is serial or parallel. Be as specific as you can. You may include pictures/diagrams in your answer. Answer on the next page. COMP 00/ 00 final exam S 0 Write your answer for Part here. COMP 00/ 00 final exam S 0 Part marks Now you need to extend your network and protocol to allow you to control all four traffic light discoboards at the four-way intersection illustrated. Describe how the discoboards will be connected and how your new protocol allows you to control the signals of each traffic light discoboard independently. Describe the topology of your network, and discuss how the traffic light discoboards are ad- dressed independently. Be as specific as you can. You may include pictures/diagrams in your answer. COMP 00/ 00 final exam S 0 Part marks Explain the main roles of the operating system in a computer system. Be as specific as you can. You may include pictures/diagrams in your answer. COMP 00/ 00 final exam S 0 Part marks Computer processors, including the discoboard’s ARM Cortex-M , use pipelining to accel- erate execution by overlapping the calculation of instructions. For example, a three-stage pipeline might look like this: What hazards can occur during instruction pipelining, and what workarounds can be ap- plied tomitigate these? Be as specific as you can. Youmay include pictures/diagrams in your COMP 00/ 00 final exam S 0 Note: you don’t have to use all of the following pages for your answer—the extra pages are included in case you need them for other questions (as described on the title page). COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0 COMP 00/ 00 final exam S 0