Worksheet 1
Worksheet 1
Worksheet 1:
MOVING DATA OPERATIONS
Sr. Programs
No.
1. Move the contents of one 16-bit variable Value to another 16-bit variable Result.
2. From the bitwise complement of the contents of the 16-bit variable Value.
3. Add the contents of the 32-bit variable Value1 to the contents of the 32-bit variable Value2 and place
the result in the 32-bit variable Result.
4. Add two numbers and store the result using offset addressing instead of immediate addressing.
5. Shift the contents of the 16-bit variable Value to the left one bit. Store the result back in Result.
6. Disassemble a byte into its high and low order nibbles
7. Find the larger of two 32-bit variables Value1 and Value2. Place the result in the variable Result.
Assume the values are unsigned.
8. Calculate the factorial of the 8-bit variable Value from a table of factorials Data Table. Store the result
in the 16-bit variable Result. Assume Value has a value between 0 and 7.
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.1
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 1: Move the contents of one 16-bit variable Value to another 16-bit variable Result.
Sample Problem:
Input: Value = C123
Output: Result = C123
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R1, Value ; Load the value to be moved
LDR R2,=Result
STR R1, [R2] ; Store it back in a different location
Here B Here
END
Result:
PRE: POST:
Value= C123 Value= C123
Result = 0 Result= C123
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.2
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.3
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 3: Add the contents of the 32-bit variableValue1 to the contents of the 32-bit variable Value2
and store the result.
Sample Problem:
Input: Value1 = 37E3C123
Value2 = 367402AA
Output: Result = 6E57C3CD
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R1, Value1 ; Load the first number
LDR R2, Value2 ; Load the second number
ADD R1, R1, R2 ; ADD them together into R1 (x = x + y)
LDR R3, Result
STR R1, [R3] ; Store the result
Value1 DCD &37E3C123 ; First value to be added
Value2 DCD &367402AA ; Second value to be added
Result DCD 0x40000000 ; Storage for result
END
Result:
PRE: POST:
Value1 = 37E3C123 Value1 = 37E3C123
Value2 = 367402AA Value2 = 367402AA
Result = 0 Result = 6E57C3CD
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.4
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 4: Add two numbers and store the result using offset addressing instead of immediate
addressing.
Sample Problem:
Input: Value1 = 37E3C123
Value2 = 367402AA
Output: Result = 6E57C3CD
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R0, =Value1 ; Load the address of first value
LDR R1, [R0] ; Load what is at that address
ADD R0, R0, #0x4 ; Adjust the pointer
LDR R2, [R0] ; Load what is at the new address
ADD R1, R1, R2 ; ADD together
LDR R0, Result ; Load the storage address
STR R1, [R0] ; Store the result
Here B Here
Value1 DCD &37E3C123 ; First value
Value2 DCD &367402AA ; Second value
Result DCD 0x40000000 ; Space to store result
END
Result:
PRE: POST:
Value1 = 37E3C123 Value1 = 37E3C123
Value2 = 367402AA Value2 = 367402AA
Result= 0 Result = 6E57C3CD
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.5
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 5: Shift the contents of the 16-bit variable Value to the left one bit. Store the result back in
Result.
Sample Problem:
Input: Value = 4242 (0100 0010 0100 00102)
Output: Result = 8484 (1000 0100 1000 01002)
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R1, Value ; Load the value to be shifted
MOV R1, R1, LSL #0x1 ; SHIFT LEFT one bit
LDR R3, Result
STR R1, [R3] ; Store the result
Here B Here
Value DCD &4242 ; Value to be shifted
Result DCD 0x40000000 ; Space to store result
END
Result:
PRE: POST:
Value = 4242 (0100 0010 0100 00102) Value = 4242 (0100 0010 0100 00102)
Result = 0 Result = 8484 (1000 0100 1000 01002)
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.6
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 6: Disassemble a byte into its high and low order nibbles
Sample Problem:
Input: Value = 5F
Output: Result = 050F
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R1, Value ; Load the value to be disassembled
LDR R2, Mask ; Load the bitmask
MOV R3, R1, LSR #0x4 ; Copy just the high order nibble into R3
MOV R3, R3, LSL #0x8 ; Now left shift it one byte
AND R1, R1, R2 ; AND the original number with the bitmask
ADD R1, R1, R3 ; Add the result of that to
LDR R0, Result
STR R1, [R0]
Here B Here
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.7
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 7: Find the larger of two 32-bit variablesValue1andValue2. Place the result in the variable
Result. Assume the values are unsigned.
Sample Problem:
Input: Value1 = 12345678
Value2 = 87654321
Output: Result = 87654321
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R1, Value1 ; Load the first value to be compared
LDR R2, Value2 ; Load the second value to be compared
CMP R1, R2 ; Compare the values
BHI Done ; If R1 contains the highest
MOV R1, R2 ; otherwise overwrite R1
Done
LDR R3, Result
STR R1, [R3] ; Store the result
Here B Here
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.8
ARM MICROCONTROLLER LAB FILE Worksheet 1: Moving Data Operations
Program 8: Calculate the factorial of the 8-bit variable Value from a table of factorials Data Table.
Store the result in the 16-bit variable Result. Assume Value has a value between 0 and 7.
Sample Problem:
Input: FTABLE = 0001 (0! = 110)
= 0001 (1! = 110)
= 0002 (2! = 210)
= 0006 (3! = 610)
= 0018 (4! = 2410)
= 0078 (5! = 12010)
= 02D0 (6! = 72010)
= 13B 0 (7! = 504010)
Value = 05
Output: Result = 0078 (5! = 12010)
Code:
AREA Program, CODE, READONLY
ENTRY
Main
LDR R0, =DataTable ; Load the address of the lookup table
LDR R1, Value ; Offset of value to be looked up
MOV R1, R1, LSL #0x2 ; Data is declared as 32bit – need to quadruple the
; offset to point at the correct memory location
ADD R0, R0, R1 ; R0 now contains memory address to store
LDR R2, [R0]
LDR R3, Result ; The address where we want to store the answer
STR R2,[R3] ; Store the answer
Here B Here
DataTable DCD &1 ;0! = 1 ; The data table containing the factorials
DCD &1 ;1! = 1
DCD &2 ;2! = 2
DCD &6 ;3! = 6
DCD &24 ;4! = 24
DCD &120 ;5! = 120
DCD &720 ;6! = 720
DCD 5040 ;7! = 5040
Value DCB &7
ALIGN
Result DCD 0x40000000
END
Result:
PRE: POST:
Value = 05 Value = 05
Result = 0 Result = 0078 (5! = 12010)
MKC M.Tech(Embedded Systems) [2nd Semester- ARM Laboratory], School of Electronics, Devi Ahilya University 1.9