You are on page 1of 2

Homework #2 Due: Sept.

16 9 am Solutions
Questions may not all be graded.
1. Suppose r0 = 0x2000000 and r1 = 0x02468ACE, with all bytes in memory
initialized to 0x00. If the following program is assembled and runs
successfully, what are the changed values in memory, r0, and r1? Use a table
to show the changed memory values. 1*18 = 18
STR r1, [r0], #4
STR r1, [r0, #0x4]!
STR r1, [r0, #0b100]

0x20000000 0xCE 0x20000008 0x CE


0x20000001 0x8A 0x20000009 0x 8A
0x20000002 0x46 0x2000000A 0x 46
0x20000003 0x02 0x2000000B 0x 02
0x20000004 0x00 0x2000000C 0x CE
0x20000005 0x00 0x2000000D 0x 8A
0x20000006 0x00 0x2000000E 0x 46
0x20000007 0x00 0x2000000F 0x 02
r0 = 0x20000008 r1 = 0x02468ACE

2. The LSL and LSR instruction components can speed up execution for some
multiplications. Show the use of LSL or LSR in instructions to perform each of
the following actions: 2*3 = 6
a. r3 = 5* r1 ADD r3,r1,r1,LSL#2
b. r2 = (3/4)*r4 SUB r2,r4,r4,LSR#2
c. r5 = 15*r0 RSB r5,r0,r0,LSL#4

3. Suppose r0 = 0xF0F0F0F0 and r1 = 0xFEDCBA98. Find the result of each of


the following (independent) operations: 4*5 = 20
a. EOR r3, r1, r0 r3 = 0X0E2C4A68
b. ORR r3, r1, r0 r3 = 0XFEFCFAF8
c. AND r2, r1, r0 r2 = 0XF0D0B090
d. BIC r1, r0 r1 = 0X0E0C0A08
e. MVN r1, r0 r1 = 0X0F0F0F0F
4. Write an assembly program that calculates the value of the following
polynomial, assuming signed integers x and y are stored in registers r0 and r1
respectively. Test this programs for x values of 2, -5, and 10 using the TIVA
board. What are the resulting values of y for these three x values? How many
multiply instructions are needed? State to the grader whether you have actually
tested your program. 20
y = 3x3 7x2 +10x 12

x = 2, y = 4;
x = -5, y = -612;
x = 10, y = 2388;

5. Write two assembly programs that reverses the byte order of register r1, first
with and then without using the REV instruction. 20

6. Suppose r0 = 0xFFFFFFFF, r1 = 0x00000001 and r2 = 0x00000000. Initially


N=Z=C=V=0. Find the new values of N, Z, C, and V running each 4*4 = 16
following instructions independently (i.e. same starting values for each case)
a. ADD r3, r0, r2 N =0,Z=0,C=0,V=0
b. SUBS r3, r0, r0 N =0,Z=1,C=1,V=0
c. ADDS r3, r2, r0 N =1,Z=0,C=0,V=0
d. LSL r3, r0, #1 N =0,Z=0,C=0,V=0

You might also like