CS计算机代考程序代写 arm assembly COMP / Mid-Semester Exam

COMP / Mid-Semester Exam

Semester

Name:

Student ID:

Time: minutes reading, minutes writing

Totalmarks:

Permittedmaterials: double-sided A cheat sheet

Instructions:

Questions are not equally weighted, and the sizes of answer boxes do not necessarily relate
to the number of marks given for this 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 simple, concrete answers thanvague, ramblingones. Marks
may be deducted for providing information that is irrelevant to a question.

For examiner use

COMP 00/ 00Mid-Semester Exam S 0

Question : Code Comprehension ( marks)
.syntax unified
.global main

.macro foo bar
ldr r1, [\bar]
ldr r2, [\bar, #4]
cmp r1, r2
beq end

.endm

main:
ldr r0, =numbers

label1:
foo r0
add r0, #4
b label1

end:
b end

.data
numbers:

.word 2, 3, 0, 0, 6, 3, 0, 0

Part ( marks)
Once this program reaches the end: label, what values will be in r1 and r2?

Answer:

Part ( marks)
In one English sentence, what does this ARM assembly program do?

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Question : Defuse theBomb ( marks)

You’re a bomb defusal expert, and you come across this device. The four digits at the bot-
tom represent a -bit binary counter which will count down from (as shown) to ,
with the least significant bit on the right. The bomb will explode when its “input wire” is .

Part ( marks)
At what counter value will the bomb go off? Explain your answer.

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Part ( marks)
Imagine you have one battery which you can attach to one of the counter bits to keep it at 1
regardless of the state of the counter. Is there a single counter bit you could attach it to to
stop the bomb going off? Explain your answer.

Answer:

Part ( marks)
Assume the values of the four counter bits are in the registers r0 to r3 as shown. Write a
small ARM assembly program to calculate the value (0 or 1) of the bomb wire and store it in
r4.

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Question : -segment display ( marks)

You’ve been asked to program a hardware device with a four-digit display like the one
above. The device is just like your discoboard but with an additional -bit display register
dr which controls the display. For example, if the “A” bit is , the top segment of the display
will be on, if the “A” bit is , it’ll be off (all but the lowest bits are unused). Each byte of the
register controls the segments for a different display digit.

G F E D C B A

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
digit 3 digit 2 digit 1 digit 0

G F E D C B AG F E D C B AG F E D C B A

This is what all the digits – should look like on this display.

COMP 00/ 00Mid-Semester Exam S 0

Part ( marks)
In ARMassembly, write a short programwhich uses the dr register to show the number 7019
on the display.

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Part ( marks)
Write a new ARM assembly program which takes a decimal number (i.e. – ) in the regis-
ter r0 and displays it on the right-most digit of the display. Make sure you include labels &
comments to structure your code.

Question: should this question require handling a -digit number, e.g. passed in through registers
r0- ? Or is it a good level as-is?

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Question : Function calling conventions ( marks)

Part ( marks)
Write an ARM assembly program which contains a function which implements Einstein’s
famousE = mc2 equation, passing arguments & and returning the result using registers.

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Part ( marks)
Re-implement theE = mc2 program, but this time passing arguments & and returning the
result on the stack.

Answer:

COMP 00/ 00Mid-Semester Exam S 0

Answer:

COMP 00/ 00Mid-Semester Exam S 0

COMP 00/ 00Mid-Semester Exam S 0

COMP 00/ 00Mid-Semester Exam S 0

COMP 00/ 00Mid-Semester Exam S 0

COMP 00/ 00Mid-Semester Exam S 0

COMP 00/ 00Mid-Semester Exam S 0