Microcontroller & Embedded Systems
1. Write ARM assembly language program to find largest/smallest value from given two numbers.
AREA bigger, CODE, READONLY
ENTRY
MAIN
LDR R1, Value1 ;load first value to be compared
LDR R2, Value2 ;load second value to be compared
CMP R1, R2 ;compare them
BHI DONE ;if R1 contains the highest
MOV R1, R2 ;otherwise overwrite R1
DONE
STR R1, Result ;store the result
SWI &11
Value1 DCD &12345678 ;value to be compared
Value2 DCD &87654321 ;value to be compared
Result DCD 0 ;space to store result
END
2. Write ARM assembly language program to find average of two numbers.
AREA Average, CODE, READONLY ; name code block
ENTRY ; marker of first executable instruction
start
ADR r1, FIRSTNUM ; load first address into r1
ADR r2, SECONDNUM ; load second address into r2
ADR r3, AVGRESULT ; load result address into r3
LDR r4, [r1] ; load first number into r4
LDR r5, [r2] ; load second number into r5
ADD r0, r4, r5 ; add numbers together
MOV r0, r0, ASR#1 ; divide by two using arithmetic shift
STR r0, [r3] ; store result to address pointed to by r3
SWI 0x11 ; terminate the program
FIRSTNUM DCD &20
SECONDNUM DCD &50
AVGRESULT DCD &0
END ; marks the end of the file
1. Write ARM assembly language program to find largest/smallest value from given two numbers.
AREA bigger, CODE, READONLY
ENTRY
MAIN
LDR R1, Value1 ;load first value to be compared
LDR R2, Value2 ;load second value to be compared
CMP R1, R2 ;compare them
BHI DONE ;if R1 contains the highest
MOV R1, R2 ;otherwise overwrite R1
DONE
STR R1, Result ;store the result
SWI &11
Value1 DCD &12345678 ;value to be compared
Value2 DCD &87654321 ;value to be compared
Result DCD 0 ;space to store result
END
2. Write ARM assembly language program to find average of two numbers.
AREA Average, CODE, READONLY ; name code block
ENTRY ; marker of first executable instruction
start
ADR r1, FIRSTNUM ; load first address into r1
ADR r2, SECONDNUM ; load second address into r2
ADR r3, AVGRESULT ; load result address into r3
LDR r4, [r1] ; load first number into r4
LDR r5, [r2] ; load second number into r5
ADD r0, r4, r5 ; add numbers together
MOV r0, r0, ASR#1 ; divide by two using arithmetic shift
STR r0, [r3] ; store result to address pointed to by r3
SWI 0x11 ; terminate the program
FIRSTNUM DCD &20
SECONDNUM DCD &50
AVGRESULT DCD &0
END ; marks the end of the file