16 32 r0 RTN Program Counter or PC: CPE 221 Test 1 Solution Spring 2019
16 32 r0 RTN Program Counter or PC: CPE 221 Test 1 Solution Spring 2019
This test is closed book, closed notes. You may not use a calculator. You should have the 6 page ARM
Instruction Reference. You must show your work to receive full credit.
6. (10 points) Convert decimal +508 and -193 to binary, using signed-2’s complement
representation and enough digits to accommodate the numbers.
0 1
16 1 15 0 12
16 31 12 16 12 1
16 508 16 193
+508 = 0x1FC = 0001 1111 1100 in 12 bits, the minimum number necessary
to represent +508 is 10 bits
+193 = 0xC1 = 0 1100 0001
-193 = 1 0011 1111
7. (3 points) What is the decimal equivalent of 0101004 (assume positional notation and unsigned
integer formats)?
0101004 = 0 x 45 + 1 x 44 + 0 x 43 + 1 x 42 + 0 x 41 + 0 x 40 = 0 + 256 + 0 + 16 + 0 + 0 = 272
8. (12 points) If r1 = 0x000F 0FFF and r2 = 4, what is the value of r0 after each of the
following instructions has been executed? Assume that each instruction uses the same data.
(a) ADD r0, r1, r1, LSL #7
r1 0000 0000 0000 1111 0000 1111 1111 1111
+r1 LSL #7 0000 0111 1000 0111 1111 1111 1000 0000
0000 0111 1001 0111 0000 1111 0111 1111 (0x0797 0F7F)
Page 1 of 4
CPE 221 Test 1 Solution Spring 2019
9. (10 points) For each of the following operations on 6 bit signed numbers, calculate the values of
the C, Z, V, and N flags
Page 2 of 4
CPE 221 Test 1 Solution Spring 2019
11. (25 points) Consider the following ARM program. Trace the values of the registers shown as they
change during program execution. Also, trace the writes to memory by any STR instructions.
There may be unused columns or rows in the tables. If you need to add columns or rows, you
may do so. DCD 1 reserves one word of storage and sets it equal to 1. SPACE 3 reserves 3 bytes
of memory but does not give those bytes a value.
AREA PROB_11, CODE, READONLY
ENTRY
ADR r10, x ; 0
ADR r11, y ; 4
LDR r0, size ; 8
MOV r1, #0 ; 12
MOV r2, #5 ; 16
Loop CMP r1, r0 ; 20
BGE done ; 24
SUB r3, r0, r1 ; 28
STR r3, [r10, r1, LSL #2] ; 32
SUB r3, r2, r1 ; 36
STR r1, [r11, r3, LSL #2] ; 40
ADD r1, r1, #1 ; 44
B loop ; 48
done B done ; 52
size DCD 6 ; 56
x SPACE 24 ; 60
y SPACE 24 ; 84
END
r0 6
r1 0 1 2 3 4 5 6
r2 5
r3 6 5 4 3 2 1 0
r10 60
r11 84
Page 3 of 4
CPE 221 Test 1 Solution Spring 2019
12. (20 points) Complete the ARM assembly language program below so that it implements the
following C++ statements.
Page 4 of 4