COMP / Final Exam
Student ID:
Time: minutes reading, minutes writing
Totalmarks:
Weighting: %
Permittedmaterials: double-sided A cheat sheet
Make sure you read each question carefully. 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.
Greater marks will be awarded for short, concrete answers than long, vague/rambling ones.
Marks may be deducted for providing information that is irrelevant to a question.
For examiner use
COMP 00/ 00 Final Exam S 0
Question marks
You inherit a broken discoboard which can only execute the immediate version of the add
instruction:
add{s}
Assuming all of the registers still work, can you come up with equivalent ways of executing
the following instructions using only the add instruction above?
Part ( marks) nop
Part ( marks) mov r2, r3
COMP 00/ 00 Final Exam S 0
Part marks
In an ARM assembly program there are many different ways to change the control flow of
your program—i.e. to jump to a location other than the instruction directly following the one
being currently executed. List as many of these ways as you can.
COMP 00/ 00 Final Exam S 0
Question marks
Part marks
What are the main components of a CPU, and what are their roles?
COMP 00/ 00 Final Exam S 0
Part marks
Suppose there are twodifferentprogramming languages: LangA (a functional-style language)
and LangB (an imperative-style language). If you only see the ARM assembly code output
generated by the compiler, can you tell whether the original program was written in LangA
or LangB? If so, how? If not, why not?
COMP 00/ 00 Final Exam S 0
Question marks
Part marks
Many programming languages have a do-while loop, which executes the loop body repeat-
edly until a certain condition is false (the conditional check occurs a ter the body is executed).
Here’s an example in C:
a = a + b;
b = 2 * b;
}while(b < a) Write a dowhile ARM assembler macro which performs a do-while loop (not for the spe- cific C example above, but for any body & condition). COMP 00/ 00 Final Exam S 0 Part marks cmp r0, r1 mov r2, r0 ldr r3, [sp, #4] mul r3, r2, r3 ldr r3, [sp] mov r0, r3 add sp, #8 Write a short program in a programming language of your choice whichmight have com- piled down to the above ARM assembly code (you may assume that the ARM code uses the standard ARM calling convention). Don’t worry if you can’t remember the exact syntax for your programming language, it’s what it does that’s important. COMP 00/ 00 Final Exam S 0 Question marks A discoboard is running a lightweight multi-tasking OSwhich supports two concurrent pro- cesses, eachwith its ownstack: thebase stackaddress is0x20000010 for stack and0x20000020 for stack . This memory layout is shown in the figure below (each box represents a -bit initial stack initial stack mul r0, r0, r0 square_plus_c: ldr r1, [sp] add r0, r1 add sp, #8 COMP 00/ 00 Final Exam S 0 Part marks If process runs just the square_plus_c function as listed, will this affect the code running in process ? Be as specific as you can—provide short code snippets or diagrams where nec- COMP 00/ 00 Final Exam S 0 Part marks In general, how could youmodify the OS so that different process stacks don’t interfere with each other? You may give multiple answers—be as specific as you can, including diagrams and/or assembly code snippets where necessary. COMP 00/ 00 Final Exam S 0 Question marks Part marks Your discoboard is going to be connected up (by some jumper cables) to a different device with a different architecture (i.e. not ARMv ). One thing you know about the other device is that it uses the opposite endianness to your discoboard. Write an ARM assembly program for your discoboard which takes a -bit value inr0andrearranges thebits to represent the same -bit valueusing theopposite endianness— store the result in r1. COMP 00/ 00 Final Exam S 0 Part marks The other device runs at Hz—much slower than your discoboard. You’ve been given the job of writing a program to process data coming from this external device. Describe at least two different approaches you could use to do this in anARMassembly pro- gram, anddiscuss the pros& cons of each approach. Youmayuse diagramsor short assembly code snippets if necessary. COMP 00/ 00 Final Exam S 0 Question marks A large bank is re-designing their banking software to run on a discoboard using a multi- taskingOS.They’ve employedyou toadvise themonsecurity issues inbuilding thisdiscoboard- powered banking system. The deposit function looks like this: push {r0} @ store deposit amount on the stack @ get the memory address where the current account balance is @ stored - the address is returned in r0 bl get_balance_address @ read current balance ldr r1, [r0] @ get deposit amount (original argument, now on stack) ldr r2, [sp] @ add deposit amount to balance add r1, r2 @ store updated balance str r1, [r0] add sp, #4 COMP 00/ 00 Final Exam S 0 Part marks Is this code safe to run in amulti-tasking OS (i.e. withmultiple processes which can each call the deposit function)? If not, what can go wrong? Be as specific as you can—provide short code snippets or diagrams where necessary. COMP 00/ 00 Final Exam S 0 Part marks How could youmodify the deposit function so that it was safe to use in amulti-tasking OS? Be as specific as you can—provide short code snippets or diagrams where necessary. COMP 00/ 00 Final Exam S 0 Question marks What are the differences between an architecturewhich uses hyper-threading vs an architec- ture which uses a vector processing unit? What use cases is each one best suited to? Explain your answer. 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