Académique Documents
Professionnel Documents
Culture Documents
Question 1
Find the mnemonic(s) for an instruction(s) from the Thumb2 instruction set for each of the
following actions.
a
move (immediate) writes an immediate value to the destination register. It can optionally update
thecondition flags based on the value.
The above move instruction moves immediate 3-bit value to a register. The immediate value can be
moves to the registers in the range to . The immediate value is in the range of 0 ± 255.
-
(0<rd<7, 0<#imm12<4095)
For a larger value (over 8 bits) we use the wide instruction.As we can see the above instruction
moves immediate 12-bit value to a register. The immediate value is in the range of 0-4095. This
instruction saves the data in the lower half of the register.
For immediate instructions which are 32-bit wide, we use the ³´. In the above instruction the
immediate instruction is forced to be used as a 32-bit instruction.
Another set of instruction can be used to set the upper half or lower half of the register. It is
generally used to set the 32-bit instructions. Here a pneumonic is illustrated to show the immediate
data stored in the upper half of the register.
b)? Add O to the value in register and put the sum in register .
This instruction adds 3-bit immediate value to a register value, and writes the result to the
destination register. It can optionally update the condition flags based on the result.
V
c
a
O
Add with Carry (immediate) adds an immediate value and the carry flag value to a register value,
and writes the result to the destination register. It can optionally update the condition flags based on
the result. The above instruction adds a 3-bit immediate value to a register along with the carry.
The above instruction adds a 32-bit immediate constant to the value in the register. In the above
instruction a 3-bit data is added as a 32-bit data, showing the different method of adding an
immediate value.
For an immediate constant more than 3-bit, we can use the wide instruction which can add 12-bit
immediate data. In the above instruction a 3-bit data is added as a 12-bit data, showing the different
method of adding an immediate value.
c)? aubtract V V from the value in register and put the difference in register
.
The instruction subtracts an immediate value from the value in register r9 and stores the result in
register r2. The immediate value is 291210, the converted bits are as showed below.
V V
O
VVVVV
This instruction subtracts wide immediate value (more than 3-bits) from a register value, and writes
the result to the destination register. It can optionally update the condition flags based on the result.
This instruction subtracts 32 bit immediate data from the value in register r9 and stores the result in
register r4.
This instruction subtracts 32 bit immediate data and any borrow from the value in register r9 and
stores the result in register r4.
2
c
d)? aubtract the value in register from O V V and put the difference in
register V.
This instruction subtracts the value in r8 from the 32-bit immediate value #0xAB00AB00. The 32-
bit immediate is
In these instructions the 32-bit immediate value is moved to a register r5 first, then the we reverse
subtract the value in r8 from r5 and store the result in register r1.
multiply the value in register with the value in register and put the product in
register .
m r4, r0, r4
multiply multiplies two register values. The least significant 32 bits of the result are written to the
destination register. These 32 bits do not depend on whether signed or unsigned calculations are
performed. It can optionally update the condition flags based on the result.
The preferred instructions for the above questions are as mentioned below in the table
j
c
ti 2
3i t i t i i t ti i W t i t ti i
i l l i t i t i t ti i ti i t
i t ti
a
t it t
i
it ti
t
i
i
t ti
itt
i
i
t i
t
t t i ti
li
t t i
t ti
t i t i
i
ill
tt
l
a
a
a
a
a
? m
i
i
t
t ti
i
m
m i
ti
i
t ti
i
ti
l
t t i
i
l
3
3
m
[
c
i
t ti
i
c
m i
ti
i
t ti
i
ti
l t t i
i
l
3
3
c
i
t ti
i
a
m i
ti
i
t ti
i
ti
l t t i
i
l
3 !
"#$
i !
! #
3
a
u
c
i
t ti
i
Aa #a cc i
ti
i
t ti
i
ti
l t t i
i
l
3 %
&"#$
t i
t $a il $a i
t t
it i
i t
t l i
t l
it i
t
t
i a !
! #
3
Aa$acc
i
t ti
i
m i
ti
i
t ti
i
ti
l
t t i
i
l
3 %
#'
3 (
m
O
!"
c
Question 3
Ôxplain the difference between the divide instructions and a Illustrate your answer by
performing the following calculations; and , using both UDIV and aDIV where X is your
student ID number, Y = -X in 32 bit 2¶s complement format and Z is the 0x000000zz where zz is
the AaCII code for the first letter in your family name.
a In the A!mv7-m profile, the Thumb instruction set includes signed and unsigned integer
divide instructionsthat are implemented in hardware. The two instructions are
? a
aigned Divide divides a 32-bit signed integer register value by a 32-bit signed integer register
value, and writes the result to the destination register. The condition code flags are not affected.The
assembler syntax is aDIA,An,A.
?
Unsigned Divide divides a 32-bit unsigned integer register value by a 32-bit unsigned integer
register value, and writes the result to the destination register. The condition code flags are not
affected. The assembler syntax is DI A, An, A.
If the value in A is not divisible by the value in A, the result is rounded toward zero. This holds
good for both the UDIV (unsigned division) and the aDIV (signed division) instructions,
Y= -X =4094197988 10 = F40880Ô4 H.
!
c
a
X= 200708279 10 = 0BF77FIC H
X= 0BF77FIC H = 40880Ô4 H
Y= -X =4094197988 10 = 0BF77F1C H
Question 4
The following program performs a mathematical operation on the values in r1 and r2 to give the
value in r0. Find the mathematical function that describes the value in ro and plot the graph for r0
against r1 for r1 in the range -20 to 20 (as a two¶s complement number) and for r2=0. 1. 2.
The above code generates a hyperbola, the value of r0 is a shown below. The value of r1 varies
from -20 to +20, the value in r1 is added to immediate value µ ¶ and the value is compared with µ¶
as seen in the code. Depending on the value of r3 the corresponding instructions are executed.
V ; we see the value in r3 is always negative. Hence the following instructions are executed.
a V
O
O O
The corresponding value in r0 is
O
V
VV
+
c % &' ( )*
* )' * , '& - -
3 i
t
%& %&
a
O
OO
i
l i
i
O !!"#$! ##
3
4
5
78
1 6 1 5 1 2 5 6 95
95 5
1 5
24
13
2
1
3 ) *+
+,
-
,
ti
a %
tti
t3i
i
t
i
t lli
i
t
?
?
B' i
iti
t i
t t 3i
i
t
i
t
t i
t a
it t i
itil i
t i
i
t
it t
tti l t
t
3
3i
i
i
i
' t
lti
.
+
' /0
@
c : ;< = >?
? >< ? A <; B B
Wit l
33333333(//
a!- ! /+( at
t
i
t
t
' +
m01- ! ! m
t l i
! t !
t itti
m01- ! ! m
t l i
! t !
t itti
B2 - - 4 t
3i
i
V
@
< CD