Vous êtes sur la page 1sur 10

c 



    

Question 1

Find the mnemonic(s) for an instruction(s) from the Thumb2 instruction set for each of the
following actions.

a  

a)? move V V in register .

move (immediate) writes an immediate value to the destination register. It can optionally update
thecondition flags based on the value.

-m  r5, #0x7D— (0<rd<7, 0<#imm8<255)

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.

-  


 —

This instruction moves the data to a

b)? Add O to the value in register  and put the sum in register .

cDD r7, r4, #0x06(0<rd, rn<7, 0<#imm3<6)

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.

   


O

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.

   


O

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 

a  r4, r9, #0x60

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.

a a   


 O

This instruction subtracts 32 bit immediate data from the value in register r9 and stores the result in
register r4.

a a   


 O ( = r9 í #
 O± borrow)

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.

O  V V


    

Aaa r1, r8, #0xc00c00 (r1 = #0xAB00AB00 ± r8)

This instruction subtracts the value in r8 from the 32-bit immediate value #0xAB00AB00. The 32-
bit immediate is

  


 

a a V  r1 = r5±r8

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

a ùreferred Instruction


 m  r5, #0x7D?
Ô cDD r7, r4, #0x06?
„ a  r4, r9, #0x60?
á Aaa r1, r8, #0xc00c00?
Y m  r4, r0, r4

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 t i 
 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              

?  O t t l i


i t  
t t  i
i t 

 i
t ti
i c

       m i
    ti i
t ti
i  
ti

l   t  t  i
 i  
l 

3   
               

               

 it it l !


"   i t ! "  ti
ti
i t

3   
    c

  

? at t   t l i


i t  
t t i
 i
i t


 i
t ti
i a        m i
    ti i
t ti
i  
ti

l   t  t  i
 i  
l 

3  ! 
        "#$       

         

i !
 ! #

3   
    a    

 it i it l i 


t t  it t
 i it 
  i
t  i

 

u

   

c              

? at t t l i


i t   O  
t t i
 i

i t 

 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

 it i it l i 


t t  it t
 i it

? mltil t l i


i t  it t l i
i t  
t t
  t i
i t 

 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,
   

X= 200708279 10= 0BF77FIC H

Y= -X =4094197988 10= F40880Ô4 H 32 bit 2¶s complement of X

Z= 8010= 50 H AaCI value of µ¶

For Unsigned Division ( ), we neglect the negative sign on µ¶

Y= -X =4094197988 10 = F40880Ô4 H.

X/Z = 0BF77FIC H / 00000050 H = O  

Y/Z = F40880Ô4 H / 00000050 H =  

!
 
c  

    
  a 

X= 200708279 10 = 0BF77FIC H

Y= -X =4094197988 10 = F40880Ô4 H = 32 bit 2¶s complement of X

Z= 8010 = 50 H AaCI value of µ¶

For aigned Division ( ), negative sign on µ¶ is considered.

X= 0BF77FIC H = 40880Ô4 H

Y= -X =4094197988 10 = 0BF77F1C H

X/Z = 040880Ô4 H / 00000050 H =  

Y/Z = 0BF77FIC H/ 00000050 H = O  

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.

ADD r3, r1, #2 ;comments omitted


mUL r4, r3, r3
Cmù r3, #0
ITTÔ mI
aUBmI r5, r2, #1
ADDmI r5, r5, r5
!aBùL r5, r2, #1
mUL r6, r5, r4
ADD r0, r6, #6
Finish
a  

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.

For r1 in the range -20 <= r1 < -2


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 
  %& %& 

 ;   t l i


 i l '  iti (
 t ll i
 i
t ti
  t 

a  
O 
OO

  
i
 l i
 i O !!"#$! ##

   t  tti l 


ti
i  ill tt l 


3

4

5

78  

1 6 1 5 1  2 5 6 95
  
95 5
1 5
24 
13 
2 
1 

3  ) *+
+,    
  - 
 ,  

 ti 

Wit  il   i


  

i tt l lt t 3i
 i

a
 )   it 
i
 i
t t 
t t 
 t 
 ti   
tti
  #  l lti
l t tti ll' 
t 3i
 i

   it   3i
 i 
 i      * #   + ** #, t  
i
l lt '  i
 t l t t 
 i
t 
 t i
t
t
 C
t '
 itl'

a  %
tti  t3i
 i
  t
 i
t ll i
 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

   3i


 i i i  ill tt l 

-.! ! /#( — atti


   t  t 3i
 i
m01 ! / ( — 
itili  ! it 
m01 ! /( — 
itili  ! it 
- .. ! ! ! —  t l t 
t t 3i
 i i
Cm ! /33333333( — C t l 
t 
t l 
it
// ll i
 i
t ti
  t 
l' 
t l i
! i l t

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 

Vous aimerez peut-être aussi