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

COMP / Mid-semester Exam

Semester
Student ID:

u

Reading time: minutes

Writing time: minutes

Permittedmaterials: 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

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.

3031 2829 2627 2425 2223 2021 1819 1617 1415 1213 1011 89 67 45 23 01

Part marks

What value(s), if any, when present at the input wire labelled ?, will produce a at the output
as shown?

OR

NAND

XOR

0

1

0?
NOT

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

Assuminga twos-complement representationwith afixednumberof bits (e.g. -bit), what is
the relationship (in termsof absolute value) between the largest unsigned value and the largest
signed value? Circle the correct answer.

• the largest signed value is less than half the value of the largest unsigned value

• the largest signed value is exactly half the value of the largest unsigned value

• the largest signed value ismore than half the value of the largest unsigned value

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) whichwill control how the three different lights (red,
amber and green) turn on and off.

Your discoboard has beenmodified 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:

. the red light is on if bit is set (1), and off if it is clear (0)

. the amber light is on if bit is set (1), and off if it is clear (0)

. the green light is on if bit is set (1), and off if it is clear (0)

. the value of all other bits in TLCR does not affect the operation of the traffic light in any
way

re
d

bi
t

TLCR: traffic light control register
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

am
be

r
bi

t

gr
ee

n
bi

t

There is no additional hardware to enforce the road rules, e.g. to preventmultiple 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

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

1

4

3

The -bit TLCR now controls all four traffic lights as shown:

light 1

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

light 2light 3light 4

On the next page, write a sequence of assembly instructions starting at a switch_to_green
label which:

• checks that the red lights only are on for lights and

• if that’s true, activates (turns on) the green lights only for lights and (keeping the
and lights red)

• otherwise, branch to the error loop from Part

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 0x40004200memory address, the discoboard also
allows the CPU to read andwrite 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 tomem-
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 0x40004200memory 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.

Youmust 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

Using your function f from Part write an assembly program (starting from the main label)
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