2017 Final Exam

COMP􏰀􏰁􏰂􏰂/􏰃􏰁􏰂􏰂 Final Exam 􏰀􏰂􏰄􏰅
Student ID:
Time: 􏰆􏰇 minutes reading, 􏰆􏰈􏰉 minutes writing Total marks: 􏰆􏰉􏰉
Weighting: 􏰇􏰉%
Permitted materials: 􏰆 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 two different programming 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 􏰑 􏰊 􏰇 􏰔 􏰕 􏰈 􏰖 push {lr} push {r0} push {r1} cmp r0, r1 bge L4 mov r2, r0 ldr r3, [sp, #4] mul r3, r2, r3 bL5 ldr r3, [sp] mov r0, r3 add sp, #8 pop {lr} Write a short program in a programming language of your choice which might 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 OS which supports two concurrent pro- cesses, each with its own stack: the base stack address is 0x20000010 for stack 􏰆 and 0x20000020 for stack 􏰐. This memory layout is shown in the figure below (each box represents a 􏰑􏰐-bit word). initial stack initial stack pointer 1 pointer 2 0x20000010 0x20000020 mul r0, r0, r0 bx lr square_plus_c: push {lr} push {r0} push {r1} bl square ldr r1, [sp] add r0, r1 add sp, #8 pop {lr} bx lr 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- essary. COMP􏰋􏰌00/􏰍􏰌00 Final Exam S􏰎 􏰋0􏰎􏰏 Part 􏰀 􏰒 marks In general, how could you modify 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. 程序代写 CS代考 加QQ: 749389476 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 in r0 and rearranges the bits to represent the same 􏰌􏰋-bit value using the opposite 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 an ARM assembly pro- gram, and discuss the pros & cons of each approach. You may use diagrams or 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- tasking OS. They’ve employed you to advise them on security issues in building this discoboard- powered banking system. The deposit function looks like this: 􏰆 deposit: 􏰐 push {lr} 􏰑 􏰊 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 􏰐􏰑 pop {lr} COMP􏰋􏰌00/􏰍􏰌00 Final Exam S􏰎 􏰋0􏰎􏰏 Part 􏰄 􏰄􏰂 marks Is this code safe to run in a multi-tasking OS (i.e. with multiple 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 you modify the deposit function so that it was safe to use in a multi-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 architecture which 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 COMP􏰋􏰌00/􏰍􏰌00 Final Exam 浙大学霸代写 加微信 cstutorcs COMP􏰋􏰌00/􏰍􏰌00 Final Exam COMP􏰋􏰌00/􏰍􏰌00 Final Exam 程序代写 CS代考 加微信: cstutorcs