程序代写代做 assembly COMP􏰀􏰁􏰂􏰂/􏰃􏰁􏰂􏰂 Mid-semester Exam

COMP􏰀􏰁􏰂􏰂/􏰃􏰁􏰂􏰂 Mid-semester Exam
Semester 􏰄 􏰅􏰆􏰄􏰒
Student ID:
Reading time: 􏰄􏰓 minutes
Writing time: 􏰈􏰆 minutes
Permitted materials: one A􏰉 page with notes on both sides
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.
If a question has several parts, you may answer the later parts even if you cannot answer the earlier ones.
For examiner use
􏰄
u

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam
S􏰍 􏰊0􏰍􏰗
Question 􏰏 Short answer questions (􏰁􏰂 marks total) Part 􏰏 􏰕 marks
mov r0, 115 adds r1, r0, 12
Draw the bit pattern in r0 after these instructions have been executed. 31302928272625242322212019181716151413121110 9 8 7 6 5 4 3 2 1 0
Part 􏰀 􏰕 marks
What value(s), if any, when present at the input wire labelled ?, will produce a 􏰆 at the output as shown?
0
OR
? XOR0
NOT
1
NAND
􏰅

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰁 􏰕 marks
mov r0, 0xffff mov r1, 0x15 subs r0, r1, r0
What will be the status of each of the NZCV bits in the status register after these instructions have been executed?
Part 􏰑 􏰕 marks
mov r1, 0x20000000 ldrh r0, [r1, 0x2]
.data
stuff:
.word 0xbeef, 0xdeadbeef
What value will be in r0 after this code has been executed?
􏰐

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰕 􏰕 marks
if(x>=5000){ // do stuff
}
Assuming that x is in r0, what might this “conditional check” (i.e. x >= 5000) look like in assembly code?
Part 􏰃 􏰕 marks
Assuming a twos-complement representation with a fixed number of bits (e.g. 􏰐􏰅-bit), what is the relationship (in terms of absolute value) between the largest unsigned value and the largest signed value? Circle the correct answer.
• thelargestsignedvalueislessthanhalfthevalueofthelargestunsignedvalue
• thelargestsignedvalueisexactlyhalfthevalueofthelargestunsignedvalue
• thelargestsignedvalueismorethanhalfthevalueofthelargestunsignedvalue
􏰉

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Question 􏰀 Tra􏰘fic light controller (􏰁􏰕 marks total)
red
amber
green
You have been asked to build a discoboard-based traffic light control device. Your job is to write the software (in ARMv􏰇 assembly) which will control how the three different lights (red, amber􏰄 and green) turn on and off.
Your discoboard has been modified to include a traffic light control register (TLCR) which is a 􏰐􏰅-bit register mapped to the address 0x40004200 in your discoboard’s address space which controls the operation of the traffic light:
􏰄. theredlightisonif bit􏰆isset(1),andoffifitisclear(0)
􏰅. theamberlightisonif bit􏰒isset(1),andoffifitisclear(0)
􏰐. thegreenlightisonifbit􏰄􏰔isset(1),andoffifitisclear(0)
􏰉. thevalueofallotherbitsinTLCRdoesnotaffecttheoperationofthetrafficlightinany way
TLCR: traffic light control register 31302928272625242322212019181716151413121110 9 8 7 6 5 4 3 2 1 0
There is no additional hardware to enforce the road rules, e.g. to prevent multiple lights from being on at the same time, or to make sure that there’s an amber light in sequence between the green and red lights (to give cars a chance to slow down). The operation of the lights is completely determined by the bits in the TLCR.
􏰄sometimes called the “yellow” light or the “orange” light 􏰓
green bit
amber bit
red bit

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰏 􏰏􏰂 marks
Write a sequence of assembly instructions, starting at a switch_to_red label, which acti- vates (turns on) the red light. If the light is not currently orange, the program execution should instead enter the following infinite error loop:
error:
nop
b error
􏰔

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰀 􏰏􏰂 marks
Write an updated version of the error loop from Part 􏰄 which “blinks” (repeatedly toggles between on and off) the amber light only at a frequency of approximately one toggle per sec- ond. The discoboard’s CPU runs at 􏰉MHz (􏰉 􏰆􏰆􏰆 􏰆􏰆􏰆 cycles per second). Include comments to explain your code.
􏰇

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰁 􏰏􏰂 marks
Version 􏰄 of the traffic light control device has been a huge success, and you’ve been asked to write the software for version 􏰅. This time, your discoboard controls all four traffic lights at an intersection as shown:
2
13
4
The 􏰐􏰅-bit TLCR now controls all four traffic lights as shown: 31302928272625242322212019181716151413121110 9 8 7 6 5 4 3 2 1 0
light 4 light 3 light 2 light 1
On the next page, write a sequence of assembly instructions starting at a switch_to_green label which:
• checksthattheredlightsonlyareonforlights􏰄and􏰐
• ifthat’strue,activates(turnson)thegreenlightsonlyforlights􏰅and􏰉(keepingthe􏰄
and 􏰐 lights red)
• otherwise,branchtotheerrorloopfromPart􏰄
􏰒

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam
S􏰍 􏰊0􏰍􏰗
􏰈

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰑 􏰕 marks
As well as being memory-mapped at the 0x40004200 memory address, the discoboard also allows the CPU to read and write the bits in this register using “bit-banding”. This is a region in the memory space (starting at 0x40014200) where each memory address refers to (and affects) only one bit in the TLCR, e.g. 0x40014200 is the bit-band address of bit 0 of the TLCR, 0x40014201 is the bit-band address of bit 1 of the TLCR, etc.
Loads from memory addresses in this bit-banding region leave the single “read” bit in the least-significant bit of the destination register (and pad the rest with zeroes). Stores to mem- ory addresses in this bit-banding region store only the least-significant bit in the source reg- ister.
What (if any) are the advantages of manipulating TLCR via this bit-banding memory region, as opposed to the usual 0x40004200 memory address? List as many as you can.
􏰄􏰆

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Question 􏰁 Functions (􏰁􏰕 marks total) Part 􏰏 􏰀􏰂 marks
f (x, y) = (42x + y)2 (􏰄)
Write an assembly function (starting at the label f) which calculates f (x, y) for any x and y expressible as 􏰐􏰅-bit signed values. Your function should use as few instructions as possible while still giving the correct answer.
You must explain (using comments) how parameters are passed into your function and how the result is returned out of your function.
􏰄􏰄

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰀 􏰕 marks
UsingyourfunctionffromPart􏰄 writeanassemblyprogram(startingfromthemainlabel) which calculates the value of f (x, y) when x = 65446 and y = −1255 and leaves the result in r0.
You do not have to re-write the code for the function itself—your program can call the f func- tion you wrote in Part 􏰄 .
􏰄􏰅

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam S􏰍 􏰊0􏰍􏰗
Part 􏰁 􏰏􏰂 marks
What are the advantages and disadvantages of passing arguments on the stack vs in regis- ters? In what situation is it preferrable to use each method? Explain your answer.
􏰄􏰐

COMP􏰊􏰋00/􏰌􏰋00 mid-semester 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 mid-semester exam
S􏰍 􏰊0􏰍􏰗
􏰄􏰓

COMP􏰊􏰋00/􏰌􏰋00 mid-semester exam
S􏰍 􏰊0􏰍􏰗
􏰄􏰔