Skip to main content Contents
Prev Up Next \(\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 9.2 Common Instructions
Exercise 9.2.1 . Limitations of Operand Usage.
Which of the following are valid ARM instructions? Select ALL that apply.
add x0, #8
Correct!
add x0, [x8]
Incorrect. Need to load from memory before you can use a value.
add x0, x8
Correct!
add #8, x0
Incorrect. Source and destination are switched.
ldr x0, [x8]
Correct!
Exercise 9.2.2 . Understanding Addressing Modes, Program Stack.
Given the following assembly code:
sub sp, sp, #8
str x29, [sp]
mov x29, sp
str x0, [x29, #-8]
(a)
Select all the statements that are true when the following instructions are executed:
sub sp, sp, #8
str x29, [sp]
The call stack is updated
Correct!
The value in register sp
is updated.
Correct!
The value in register x29
is updated.
Incorrect.
(b)
Select all the statements that are true when the following instruction is executed:
mov x29, sp
The call stack is updated.
Incorrect.
The value in register sp
is updated.
Incorrect.
The value in register x29
is updated.
Correct!
(c)
Select all the statements that are true when the following instruction is executed:
str x0, [x29, #-8]
The value in register x0
is updated.
Incorrect.
The call stack is updated.
Correct!
The value in register x29
is updated.
Incorrect.
Exercise 9.2.3 . Practice Tracing Assembly.
Given the following register table populated with initial values:
sp
0xac0
x29
0xae0
x0
0xf1
x1
0xe2
For each location, indicate (in hex) the values stored after the following instructions are executed:
sub sp, sp, #8
str x29, [sp]
mov x29, sp
str x1, [x29, #-8]
ldr x0, [x29, #-8]
sub x0, x0, #2
Exercise 9.2.4 . Practice Tracing Assembly.
Given the following register table populated with initial values:
sp
0xac0
x29
0xae0
x0
0x2c
x1
0x28
x2
0x20
Indicate (in hex) the values stored in memory and the register table after the following instructions are executed:
sub sp, sp, #0x8
str x29, [sp]
mov x29, sp
str x1, [x29, #-0x8]
str x2, [x29, #-0x10]
ldr x0, [x29, #-0x8]
sub x0, x0, x2
ldr x29, [sp]
add sp, sp, #0x8
Call Stack (Grows toward lower addresses)
Register Table
Hint . Consider drawing out the stack by hand to aid you in solving this problem.
Answer . Click
here to use ASM Visualizer to trace of the code. Note that the trace shows the full stack addresses, while we only show the lower two bytes of the addresses in the example above.
Exercise 9.2.5 . Understanding Addressing Modes, how operations affect registers and memory. Also addresses the use of the x29 register..
Given the following values in memory:
0xe3a8: 0x20
0xe3b0: 0x28
0xe3b8: 0x0
0xe3c0: 0xe3e0
Suppose register x29 contains the value 0xe3c0
. Which set of instructions will add the values in memory location 0xe3b0
and 0xe3a8
together and store the result in the register x0?
ldr x1, [x29, #0x10]
ldr x2, [x29, #0x18]
add x0, x1, x2
Incorrect.
ldr x1, [x29, #0x10]
ldr x2, [x29, #0x18]
add x0, x1, x2
Correct!
ldr x1, [x29 #-0x10]
add x0, x1, [x29, #-0x18]
Incorrect.
Exercise 9.2.6 . Understanding Addressing Modes, add
Instruction.