程序代写代做 assembly arm COMP􏰀􏰁􏰂􏰂/􏰃􏰁􏰂􏰂 Final Exam 􏰀􏰂􏰏􏰙

COMP􏰀􏰁􏰂􏰂/􏰃􏰁􏰂􏰂 Final Exam 􏰀􏰂􏰏􏰙
Student ID:
Reading time: 􏰄􏰓 minutes Writing time: 􏰄􏰒􏰆 minutes
Make sure you read each question carefully. Some words have footnotes􏰄 to clarify what 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.
Greater marks will 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 for minor syntax errors.
u
􏰄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.
Answer:
• 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 Answer:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
􏰅
mov r0, 0b10101101 mov r1, 0b00011101 lsl r1, 3
orr r0, r0, r1

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.
Answer:
• N: • Z: • C: • V: • r0:
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 needed.
mov r0, 0xfffffff0 mov r1, 0x10
adds r0, r0, r1
􏰐

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- lows):
Draw diagrams to define a circuit that is equivalent to a logical NOT gate using only NOR gates.
Answer:
Part 􏰃 􏰁 marks
Draw diagrams to define a circuit that is equivalent to a logical OR gate using only NOR gates (as defined above).
Answer:
􏰉

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 ARM Architecture 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? Answer:
• inr0
• inr1
• inr2
• inr12
• inpc
• infp
• onthestack
• inthe.datasection
􏰔

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? Answer:
• 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 function: for positive integers x and y. pow(x, y) = xy (􏰄) 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 The output of our pow function is likely to overflow, for instance, when calculating pow(2, 33). If you were 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. Answer: • Amethodtosavedatainmemorysothatnoprocesscanmodifyit. • Amethodtoensurethatonlyoneprogramcanaccessasharedresourceatatime. • Amethodtodeterminewhethertwoprogramsareaccessingmemoryatonce. • Amethodtoexcludeprogramsfromaccessingtheprivatememoryofotherprograms. • AmethodtostopmultipleprogramsfromchangingCPUregisters. • Amethodforsavingdatainbetweencontextswitches. 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 answer. Answer: • TurningonanLED. • Branchingbasedonthevalueofaregister. • Sendingdataoveranetwork. • Receivingdataoveranetwork. • Calculatingthefrequencyofamusicalpitch. • Schedulingaregularlytimedevent. • PlayingMIDInotes. • Loadingdatafrommemory. • Settingperipheralcontrolregisters. • Respondingtounexpectederrors. 􏰄􏰄 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 “a”). The program should not affect punctuation, spaces or upper-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 in memory. Write a function called encode_letter, that takes a memory location as its argument, loads and encodes the letter, and finally stores the encoded letter back in the same memory loca- tion. 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 Write your answer for Part 􏰋 here: S􏰍 􏰊0􏰍􏰚 􏰄􏰐 COMP􏰊􏰋00/􏰌􏰋00 final exam S􏰍 􏰊0􏰍􏰚 Part 􏰑 􏰕 marks Now use your encode_letter function to encode a string of characters in memory. 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 indicate what 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 for designing the physical connections between the discoboards, and software to run on them. Each of the four traffic lights contains one discoboard and can display 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 Write your answer for Part 􏰍 here. S􏰍 􏰊0􏰍􏰚 􏰄􏰇 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 to mitigate these? Be as specific as you can. You may include pictures/diagrams in your answer. 􏰅􏰆 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􏰍􏰚 􏰅􏰒