18s Cpe221 Final Solution
18s Cpe221 Final Solution
18s Cpe221 Final Solution
This test is closed book, closed notes. You may use a calculator. You should have the ARM
reference packet. You must show your work to receive full credit. Before you begin, please
make sure that you have all nine pages of the exam.
16 0 1
16 1 0
16 16 10
16 266 7
16 4263
7. (4 points) In an ARM computer, r2 contains a value of 5971 in decimal. What is the binary value
of r2 after this instruction is executed?
16 0 1
16 1 7
16 23 5
16 373 3
16 5971
r2 = 0001 0111 0101 0011 0001 0111 0101 0011 or ox1753 1753
Page 1 of 9
CPE 221 Final Exam Solution Spring 2018
8. (2 points) In an ARM computer, r2 contains a value of -4263 in decimal while r3 contains a value
of 5971 in decimal. What is the binary value of r1 after this instruction is executed?
9. (13 points) (a) (9 points) What are the values of the following registers when the program
executes “B loop” for the sixth time? Answer in decimal.
(b) (4 points) What values are written by the 56 STR r3, neg and 60 STR r4, pos
instructions? Answer in decimal.
56 STR r3, neg _3_ 60 STR r4, pos _7_
Page 2 of 9
CPE 221 Final Exam Solution Spring 2018
10. (15 points) For the architecture shown, except that the ALU has 8 possible operations, write the
concrete RTL and the sequence of signals and control actions necessary to execute the
instruction XOR R1, R0, that stores the exclusive-OR of R0 and R1 in R1.
Abstract RTL: R1 R0 R1
F2 F1 F0 Operation
0 0 0 A = B’
0 0 1 A = C’
0 1 0 A = B OR C
0 1 1 A = B AND C
1 0 0 A = B + C
1 0 1 A = B - C
1 1 0 A = B + 1
1 1 1 A = C + 1
Page 3 of 9
CPE 221 Final Exam Spring 2018
11. (10 points) A certain memory system has a 4 GB main memory and a 64 MB cache. Blocks are 8
words and each word is 32 bits. Show the fields in a memory address if the cache is 8-way set
associative. This memory system is byte addressable.
12. (6 points) If you want to build a 231 word, 128-bits-per-word memory and the only parts you
have available to you are static RAM chips that contain 218 8 bit words each. (a) (2 points) How
many rows are required? (b) (2 points) How many columns are required? (c) (2 points) How
many chips in all?
13. (6 points) A RISC processor executes the following code. There are data dependencies. A source
operand cannot be used until it has been written.
LDR r2, [r4]
MOV r3, r5
STR r6, [r2]
Assuming a five-stage pipeline (fetch (IF), operand fetch (OF), execute (E), memory access (M),
and register write (W)), how many extra cycles are required to ensure that the correct value of
r2 is available for the STR instruction? Two extra cycles are required as the STR instruction
spends three cycles in the OF stage because it has to wait on the LDR to be written in stage 5.
1 2 3 4 5 6 7 8 9
LDR r2, [r4] IF OF E M W
MOV r3, r5 IF OF E M W
STR r6, [r2] IF OF OF OF E M W
Page 4 of 7
CPE 221 Final Exam Spring 2018
14. (20 points) Complete the ARM assembly language program below so that it implements the
following C++ statements.
;
; This program examines two arrays, element by element and copies
; the larger number of each pair into a third array. It also
; writes a 0 into an array called which if the x value was
; selected in that position or a 1 if the y value was selected.
;
; const int size = 10;
; int x[size] = {100, 3, -1, 2, 4, 4, 2, -1, 3, 100};
; int y[size] = {-53, 247, 95, -7, 481, 91, -33, 1500, 29, -83};
; int z[size];
; int which[size];
; int i;
; for (i = 0; i < size; i++)
; if (x[i] > y[i]) {
; z[i] = x[i];
; which[i] = 0; }
; else {
; z[i] = y[i];
; which[i] = 1; }
Page 5 of 7
CPE 221 Final Exam Spring 2018
15. (15 points) Consider the following ARM program. Trace the stack activity, including all changes
to the stack pointer and to the contents of the stack. Clearly indicate the value of the sp.
; int main() {
; int P = 3;
; int Q = -1;
; P = Func1(P);
; Q = Func1(Q);}
; int Func1(int x) {
; if (x > 0) x = Times16(x) + 1;
; else x = 32*x;
; return(x);}
; int Times16(int x) {
; x = 16*x;
; return(x);}
Page 6 of 7
CPE 221 Final Exam Spring 2018
Page 7 of 7