Q1. (2pts) Multiplication with shift instructions
MOV R0, #97
MUL R2, R1, R0
The above code computes R2 = R1 * 97. Carry out the same computation, (i.e., a multiplication by 100)
with another code, using only LSL and ADD instructions. Don’t use any loops, (i.e., no use of branches).
The result should be placed into R2 like the original code. You may use additional registers such as R3 and
R4.
Note that you cannot run the provided code in VisUAL, because MUL is not a supported opcode in
VisUAL.
Q2. (6pts) Memory map
Let’s assume that you’re using Keil uVision. Fill out the blanks of the memory map (address 0x00000004
to address 0x00000014) when running the following assembly program.
THUMB
StackSize EQU 0x00000100
AREA STACK, NOINIT, READWRITE, ALIGN=3
MyStackMem SPACE StackSize
AREA RESET, READONLY
EXPORT __Vectors
__Vectors
DCD MyStackMem + StackSize
DCD Reset_Handler
AREA MYDATA, DATA, READWRITE
dst SPACE 8
AREA MYDCODE, CODE, READONLY
src0 DCB “CSS“, 0
src1 DCB “UWB“, 0
ALIGN
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0, =src0
LDR R1, =src1
LDR R2, =dst
loop1
LDRB R3, [R0], #1
CBZ R3, next
STRB R3, [R2], #1
B loop1
next
MOV R3, ‘.’
STRB R3, [R2], #1
loop2
LDRB R3, [R1], #1
CBZ R3, end_prog
STRB R3, [R2], #1
B loop2
end_prog
B end_prog
END
Address Contents
0x60000000
DRAM
0x40000000
Peripherals
0x20000008
SRAM
0x20000000
0x00000014 Fill in the 2–byte hex value
0x00000012 Fill in the 2–byte hex value
0x00000010 Fill in the 2–byte hex value
0x0000000C Fill in the 4–byte hex value
0x00000008 Fill in the 4–byte hex value
0x00000004 Fill in the 4–byte hex value
0x00000000 0x20000108
Q4. (12pts) Pointer operations
On slide deck 6.ARM–InstrMem, we studied how to traverse a linked list using pre–indexed/register offset
addressing. The following code intends to traverse a linked list in search for a given value in R0 and returns
the address of this value into R1 (but not the address of the node). If the value was not found, it returns 0 in
R1, (i.e., a null address).
How about traversing a binary search tree?
R0 maintains a value to search. R1 first points to the tree root and is used to access each tree node. You can
access its left pointer, right pointer, and value with
struct node {
struct node *left; // R1
struct node *right; // R1 + 4
int value; // R1 + 8
}
Using VisUAL, write a binary–tree search program. Your program searches for a value given in R0 and
returns the address of this value into R1 (but not the address of the node). If the value was not found, it
returns 0 in R1 (i.e., a null address).
Initialize a tree with the following code:
; left right value
node1 DCD 0x10C, 0x130, 4
node2 DCD 0x118, 0x124, 2
node3 DCD 0, 0, 1
node4 DCD 0, 0, 3
node5 DCD 0x13C, 0x148, 6
node6 DCD 0, 0, 5
node7 DCD 0, 0, 7
You may assume that the tree root is located at memory address 0x100.
Verify the correctness of your program with three test cases: R0 = 0, R0 = 5, and R0 = 8.
What to submit: source code, screen shorts, and short explanations
1. (6 pts) Your source code named hw3q3.s: You need to add comment to each line of your code,
otherwise, you get 0 for the coding part!
2. (6 pts) In the same file recording your answers to Q1 and Q2, add screenshots and explanations for
the following three test cases
a. Test case 1 (where R1 = 0)’s screenshot of registers (R1 – R13, LR, and PC) and a short
explanation: 2pt
b. Test case 2 (where R1 = 5)’s screenshot of registers (R1 – R13, LR, and PC) and a short
explanation: 2pt
c. Test case 3 (where R1 = 8)’s screenshot of registers (R1 – R13, LR, and PC) and a short
explanation: 2pt
d. Copy your source code to the file after the test case screenshots and explanations.