arm instructions example
TRANSCRIPT
-
8/2/2019 ARM Instructions Example
1/3
08.601: Microcontroller based System Design(S6EC)
Question: Fill the table for the following segment of code for ARM processor:
r0 = 0x00000000 r1 = 0x00000001 r2 = 0x0000000A r3 = 0x0000000F
UMLAL r0,r1,r2,r3
RSB r0,r2,r2,LSL#3
MOV r1,r0,ROR r2
BIC r0,r3,r2
CLZ r1,r2
TST r3,r0
Since it is a segment of code, each instruction depends on the previous.
Note that only the content of the destination register will change.
UMLAL : Unsigned Multiply and Accumulate Long
UMLAL r0,r1,r2,r3 : (r2xr3)+(r1,r0)
Each register is 32- bit, so product of 2 registers will result in a 64-bit number(16 hex digits).
Find r2 x r3, add the lower 32 bits to r0 and upper 32 bits to r1.
r2xr3 = 0x00000000 00000096
Lower 32 bits, ie., lower 8 hex digits: 00000096 and upper 32 bits, ie., upper 8 hex digits:
00000000
Add 00000096 to r0, add 00000000 to r1
r0 = 0x00000096 & r1= 0x00000001
No change for contents of r2 and r3
RSB : Reverse Subtract
RSB r0,r2,r2,LSL#3:
Find r2LSL#3 r2 and store the result in r0.
r2LSL#3: 0x0000000A shifted left by 3 bits becomes 0x00000050
(0x0000000A is 0000 0000 0000 0000 0000 0000 0000 1010 in binary
0000 0000 0000 0000 0000 0000 0000 1010 becomes
-
8/2/2019 ARM Instructions Example
2/3
0000 0000 0000 0000 0000 0000 0101 0000
Or
Each shifting left is equal to multiplying by 2, shifting 3 times means multiplying by 2x2x2 = 8.
Multiplying A by 8 gives hex 50).
Since it is reverse subtract, find r2LSL#3 r2.ie., 0x00000050 0x0000000A = 0x00000046
r0 = 0x00000046
r2 is not affected
MOV r1,r0 ROR r2:
Rotate the content of r0 to the right by the value in r2 and store in r1.
r0 ROR r2: r2 has the value 0x0000000A, so rotate content of r0 to the right 10 times.
0x00000046 rotated right 10 times will become 0x00000000
So r1 after the MOV will contain 0x00000000.
BIC: Bit Clear
BIC r0,r3,r2:
Identify the bit positions in r2 which are binary 1s.
Clear the bits of r3 in the corresponding positions.
r3 = 0x0000000F, ie., 0000 0000 0000 0000 0000 0000 0000 1111 in binary.
r2 = 0x0000000A, ie., 0000 0000 0000 00000 000 0000 0000 1010 in binary.
clear the bits of 0000 0000 0000 0000 0000 0000 0000 1111 corresponding to the positions of
1s in r2(bit3 and bit1).
Hence 0000 0000 0000 0000 0000 0000 0000 1111 becomes 0000 0000 0000 0000 0000 0000
0000 0101. ie., 0x00000005
Content of r0 becomes 0x00000005
CLZ: Count Leading Zeroes
CLZ r1, r2:
Count the leading binary zeroes in r2 and store the count in r1.
r2 = 0x0000000A, ie., 0000 0000 0000 0000 0000 0000 0000 1010
28 leading zeroes
Or
Before A, there are 7 hex zeroes, ie., 7x4 =28 binary zeroes.
After the execution of the instruction, r1 will have 0x0000001C(28 decimal = 1C hex).
TST: Test(doesnt change the content of any register, only affects the flags)
TST r3,r0:
Check if content of r3 and r0 are equal and update status flags accordingly.
All the registers remain the same.
-
8/2/2019 ARM Instructions Example
3/3
r0 = 0x00000000 r1 = 0x00000001 r2 = 0x0000000A r3 = 0x0000000F
UMLAL r0,r1,r2,r3 r0 = 0x00000096 r1 = 0x00000001 r2 = 0x0000000A r3 = 0x0000000F
RSB r0,r2,r2,LSL #3 r0 = 0x00000046 r1 = 0x00000001 r2 = 0x0000000A r3 = 0x0000000F
MOV r1,r0,ROR r2 r0 = 0x00000046 r1 = 0x00000000 r2 = 0x0000000A r3 = 0x0000000F
BIC r0,r3,r2 r0 = 0x00000005 r1 = 0x00000000 r2 = 0x0000000A r3 = 0x0000000F
CLZ r1,r2 r0 = 0x00000005 r1= 0x0000001C r2 = 0x0000000A r3 = 0x0000000F
TST r3,r0 r0 = 0x00000005 r1= 0x0000001C r2 = 0x0000000A r3 = 0x0000000F
(Note: Clearly understand each instruction and its usage. Then apply it to the registers, work
out yourself. Dont forget the binary, hex and decimal formats while interpreting the
digits/values. See if the answers above match with what you have got. Let me know if I have
made any mistake!!)
S. V. Rao
Dept of ECE
9446322590