An ARM-based embedded system monitors four pressure sensor readings
stored at memory locations 0x20000100, 0x20000104, 0x20000108, and
0x2000010C.
The system must perform the following operations:
[Link] the first and second sensor values and store the smaller value at
memory address 0x20000110.
[Link] the third and fourth sensor values and store the larger value at
memory address 0x20000114.
[Link] the two stored results (0x20000110 and 0x20000114).
[Link] the final sum at memory address 0x20000118.
; Load base addresses
LDR R0, =0x20000100 ; Base address of
sensors
LDR R1, =0x20000110 ;
LDR R2, =0x20000114 ;
LDR R3, =0x20000118 ;
;Load first two values
LDR R4, [R0] ; Sensor 1
LDR R5, [R0, #4] ; Sensor 2
CMP R4, R5
BGT S1_GREATER
MOV R6, R4 ; smaller value
B STORE_MIN
S1_GREATER
MOV R6, R5
STORE_MIN
STR R6, [R1]
; Load next two values
LDR R7, [R0, #8] ; Sensor 3
LDR R8, [R0, #12] ; Sensor 4
CMP R7, R8
BGT S3_GREATER
MOV R9, R8 ; larger value
B STORE_MAX
S3_GREATER
MOV R9, R7
STORE_MAX
STR R9, [R2]
; Add results
ADD R10, R6, R9
STR R10, [R3]
END
A simple window control system uses an ARM processor; write ARM assembly
instructions to open the window and indicate the status register contents for both
successful and failed operations.
MOV R0, #1 ; Load 1 (OPEN command)
MOV R1, #0 ; Clear status register value
CMP R0, #1 ; Check if command is OPEN
BEQ OPEN_WINDOW ; If equal, branch to open
B FAIL ; Otherwise, go to fail
OPEN_WINDOW
MOV R1, #1 ; Set success flag
B END
FAIL
MOV R1, #0 ; Set failure flag
END
A smart safety system uses an ARM processor to monitor a sensor value stored in register
R5. If the value equals 0x1000, a LED should glow and if it’s 0x0000 then LED should be
OFF. Write ARM assembly instructions to perform the comparison and branch to a LED
label if matched, and briefly explain how the CPSR supports this operation . Also find
content of CPSR (i.e. cpsr flag bits)
LDR R0, =0x1000 ; Load threshold value
CMP R5, R0 ; Compare sensor value (R1) with 0x1000
BEQ LED ; Branch if equal (Z flag = 1)
B END ; Otherwise continue normal flow
LED
; LED ON
MOV R2, #1 ; Example: set LED flag
END
Programs for Practice
For the following ARM program . Assume that register R5 contains memory address 4000.
Determine the final value stored at memory location 4000. Also determine the content of status register
(CPSR) (i.e. value of sign, zero, carry and overflow flag bits of cpsr)
MOV R0, #3
MOV R1, #10
MOV R2, #2
START: SUB R1, R1, R2
ADD R0, R0, #1
CMP R1, #4
BGT START
STR R0, [R5]
Q-Write an ARM assembly program to compute the factorial of a number N.
Q-Write an ARM program to calculate the sum of N elements in an array.
Assume:
Q-Write an ARM program to find the largest element in an array of N numbers