# CS代考 | Comp2300 & Comp6300 Computer Organisation & Program Execution

1. [10 marks] Digital Logic / Basic CPU architecture
(a) [5 marks] The following circuit diagram show a correctly working, 3-bit ripple-carry
(i) [2 marks] Use this adder to calculate S0 to S2 as well as C0 to C2 given the values
for A and B in the table below.

(ii) [3 mark] What arithmetic operation let to the above results S0 to S2 and what do
those C0 to C2 values tell you? If there are multiple possible options then list them all.

(b) [5 marks] The function ,, q ab c ^ h is defined by the following truth-table. Use minterms
or maxterms to determine and simplify the output q to the shortest possible form (the
smallest number of boolean operators). You can also use algebraic transformations to
simplify q. Use text notations like (x and y) or not (x) if you don’t find standard logic
operators on your keyboard.

2. [10 marks] Machine instructions
(a) [5 marks] Compile one of the following code snippets (provided in both C-style and
Algol-style syntactical forms for your convenience) into ARM assembly code and keep
the value of Power in r0.
C-style:
unsigned int Power = 1;
int i;
for (i = 1; i < 11; i++) {
Power = Power * 2;
}
Algol-style:
declare
Power : Natural := 1;
begin
for i in 1 .. 10 loop
Power := Power * 2;
end loop;
end;

(b) [4 marks] Consider the following ARM code:
ldr r0, =array
ldrb r1, [r0], #1 @ Loads a single byte from memory
loop:
ldrb r2, [r0], #1 @ Loads a single byte from memory
cmp r1, r2
beq terminate @ eq stands for “equal”
mov r1, r2
b loop
terminate:
b terminate
array:
.ascii “Helloooo”

(i) [1 mark] How many machine instructions will have been executed from the begin-
ning of this code, until it reaches terminate? If it does not reach it then say “infinite”.

(ii) [1 marks] If the label terminate is or would be reached: what is the meaning of the
value of r0 at that time?

(iii) [3 marks] Rewrite the above code using (index) register-offset addressing (instead
of post-indexed addressing). (no need to re-write or copy anything after terminate.)

E-mail: itcsdx@outlook.com  微信:itcsdx