You are on page 1of 2

Homework #1 Due: Sept 8.

(100) Solution
1. Consider the following numbers as signed. Find their equivalent
representations: (3*11=33)
a. 011011012 = 155 8 = 6D 16 = 109 10
b. B716 = 10110111 2 = -73 10
c. 111010112 = 353 8
d. 25310 = FD 16 = 011111101 2
e. 0x5C = 01011100 2
f. 0xED = -19 10
g. 10210 = 01100110 2

2. a. In ARM Cortex-M4, how many general purpose registers are there?


b. What are other names for R13, R14, and R15?
c. What is the name of the Program Status Register?
(3*3=9)
a. There are 13 general purpose registers.
b. R13: stack pointer.
R14: link register.
R15: Program counter.
c. PSR

3. a. Write the instruction(s) to add the contents of R6 to R7 and place the results
in R1. (5)
b. Write the instruction(s) to subtract 19 from the contents of register R5,
placing results back in R5. (10)

a. ADD R1,R6,R7
b. SUB R5,R5,#19
4. Solve Exercise 5.6.1.b (5.5.1.b in First Edition) in the text (4*3=12)
LDR r1, [r0, #4] R0 = 0x20008000 R1 = 79CDA3FD
LDR r1, [r0], #4 R0 = 0x20008004 R1 = 0DEB2C1A
LDR r1, [r0, #4]! R0 = 0x20008004 R1 = 79CDA3FD
5 Solve Exercise 5.6.3 (5.5.3 in First Edition) in the text (only first question #3 if
there are 2 of them in your version of text) (12)
0x20000000 0x78 0x20000008 0x 78
0x20000001 0x56 0x20000009 0x 56
0x20000002 0x34 0x2000000A 0x 34
0x20000003 0x12 0x2000000B 0x 12
0x20000004 0x00 0x2000000C 0x 78
0x20000005 0x00 0x2000000D 0x 56
0x20000006 0x00 0x2000000E 0x 34
0x20000007 0x00 0x2000000F 0x 12

6. If R1=0x80654321 and R2=0x91234567 and the instruction ADDS R0, R1,R2


is executed, give the new values of R0, R1, R2, N, Z, C, and V (R0 3, others 1,
total 9)

R0=11888888, R1=0x80654321, R2=0x91234567,N=0,Z=0,C=1,V=1

7. Assume dividend is in R0 and divisor is in R1. Write code sequence to place


quotient of these two numbers in R2 and remainder in R3, changing as few other
registers as possible. (10)

UDIV(SDIV) R2,R0,R1 UDIV(SDIV) R2,R0,R1


MUL R3,R2,R1 MLS R3,R1,R2,R0
SUB R3,R0,R3
(We only need 4 registers! )
Hint: See book P80