CS计算机代考程序代写 arm assembly algorithm The Australian National University

The Australian National University
Mid Semester Examination – April 2019

Comp2300 & Comp6300
Computer Organisation & Program Execution

Study period: 15 minutes
Time allowed: 1.5 hours (after study period)
Total marks: 50
Permitted materials: None

Questions are not equally weighted – sizes of answer boxes do not nec-
essarily relate to the number of marks given for this question.

All your answers must be written in the boxes provided in this booklet. You will be provided with scrap paper
for working, but only those 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.
Label any answer you write at the end of the booklet with the number of the question it refers to.

Greater marks will be awarded for answers that are simple, short and concrete than for answers of a sketchy and
rambling nature. Marks will be lost for giving information that is irrelevant to a question.

Student number:

The following are for use by the examiners

Q1 mark Q2 mark Q3 mark

Total mark

Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 2 of 12

1. [16 marks] Digital Logic / Basic CPU architecture

(a) [8 marks] The following circuit diagrams show a correctly working, 3-bit ripple-carry
adder.

(i) [3 marks] Use this adder to calculate 2 3+ by labelling all inputs and outputs cor-
rectly with ‘1’ or ‘0’.

A1

XOR

AND

B1

XOR

AND

OR

S1 A2

XOR

AND

B2

XOR

AND

OR

S2

C1 C2

A0

XOR

AND

B0 S0

C0

(ii) [1 mark] What is the meaning of C2 in the circuit diagram above and what does it
say about your calculation 2 3+ ?

(iii) [3 marks] Use the following adder to calculate 2 3- by labelling all inputs and out-
puts correctly with ‘1’ or ‘0’.

A1

XOR

AND

B1

XOR

AND

OR

S1 A2

XOR

AND

B2

XOR

AND

OR

S2

C1 C2

A0

XOR

AND

B0 S0

C0

(iv) [1 mark] What is the meaning of C2 in the circuit diagram above and what does it
say about your calculation 2 3- ?

Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 3 of 12

(b) [3 marks] The function , ,q a b c^ h is defined by the following truth-table. Use minterms or
maxterms to determine and simplify the output q.

a b c Output q min- or max terms Simplified min- or maxterms

F F F F

F F T F

F T F F

F T T F

T F F T

T F T T

T T F T

T T T T

(c) [3 marks] In the following circuit diagram all four inputs A, B, C, D are set to ‘1’.

XOR

AND

OR

A
B

C
D

Q

‘1’
‘1’

‘1’
‘1’

You need to change all four inputs to ‘0’ (“power down the circuit”). In which order do
you need to change those inputs to ‘0’ (“cut the wires”), such that Q never changes to
‘1’ (“bomb goes off”)? If there are multiple sequences, describe them all. You cannot
change the value of multiple inputs at the same time.

Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 4 of 12

(d) [2 marks] Which if the following statements are correct? Tick all correct statements –
marks will be subtracted for wrongly ticked statements, so do not just tick all of them.

☐ If you add two whole numbers with machine instructions, the CPU knows
whether they are natural numbers (unsigned numbers) or integers (signed num-
bers).

☐ If you add two whole numbers with machine instructions, you need to tell the
CPU whether they are natural numbers (unsigned numbers) or integers (signed
numbers).

☐ If you add two whole numbers with machine instructions, the CPU does not care
whether they are natural numbers (unsigned numbers) or integers (signed num-
bers) and will provide the result for either case.

☐ If you remove subtraction from your machine instruction set, you can theoretically
still express the same number of algorithms.

☐ If you remove conditional branching from your machine instruction set, you can
theoretically still express the same number of algorithms.

☐ If you remove function calls from your machine instruction set, you can theoreti-
cally still express the same number of algorithms.

☐ The next CPU instruction is held in the PC register.
☐ The address of the next CPU instruction is held in the PC register.

Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 5 of 12

2. [14 marks] Machine instructions

(a) [4 marks] Consider the following ARM assembly code:

mov r0, 0xFFFF
lsl r1, r0, #16
add r1, r0
adds r1, 0x01

What will be the values of the following status flags after those instructions have been
executed?

Negative (N) =
Zero (Z) =
Carry (C) =
Overflow (V) =

(b) [6 marks] Compile the following code snippet:

a = 0;
while (a < 100) { a = a + 5; } into ARM assembly code and keep the value of a in r0. You are not losing marks for minor syntax errors. Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 6 of 12 (c) [4 marks] Consider the following ARM code: ldr r0, =array ldr r4, =limiter loop: ldr r1, [r0], #4 ; r0 is incremented by #4 after load cmp r0, r4 beq done ; eq stands for “equal” ldr r2, [r0] cmp r1, r2 bls loop ; ls stands for “lower or same” mov r0, #0 b end done: mov r0, #1 end: b end array: .word 0, 2, 4, 6, 8, 19, 21, 21, 27, 28, 30 limiter: .word 0 (i) [1 mark] What do you expect the value of r0 to be after this program reached end? r0 = (ii) [3 marks] In a single English sentence: what does the value of r0 represent in the end? Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 7 of 12 3. [20 marks] Functions (a) [5 marks] Draw a diagram depicting a complete stack frame with all possible items which you might find there. If it makes your diagram more comprehensible, draw a few stack frames around it as well. Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 8 of 12 (b) [5 marks] Your local variables inside a function look like this (in two different syntacti- cal styles for you, expressing in both cases that you have a single Boolean and 10 word- sized Numbers): C-style: typedef enum {false, true} bool; bool flag; unsigned int field[10]; Algol-style: Flag : Boolean; Field : array [1..10] of Natural; (i) [2 marks] Write ARM assembly code which allocates memory space for those vari- ables and explain your answer. You are not losing marks for minor syntax errors. (ii) [3 marks] When does this allocation code need to be executed and how and when do you de-allocate those local variables again, once they are no longer needed? Give precise answers. Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 9 of 12 (c) [5 marks] Write an ARM assembly function which returns the sum of two numbers (both are parameters of your function). You are not losing marks for minor syntax er- rors. Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 10 of 12 (d) [5 marks] Write an ARM assembly function which returns the sum of an array of num- bers (which is a parameter of your function). If you need to make assumptions about the structure or definition of your array, then explain those assumptions. You are not losing marks for minor syntax errors. continuation of answer to question part continuation of answer to question part Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 11 of 12 continuation of answer to question part continuation of answer to question part Comp2300 & Comp6300 Mid-Semester Exam 2019 Page 12 of 12