Question: Modify the following code so that it LOADS the N1, N2, N3 values from MEMORY into the registers. Use a label and a .data block
Modify the following code so that it LOADS the N1, N2, N3 values from MEMORY into the registers. Use a label and a .data block to put these into three consecutive memory locations. Then store the answer into a fourth memory location immediately following the three original values; use a second label with a .skip directive or an initialized value to setup this location.
The code:
AREA example, CODE, READONLY ENTRY
; initialize the input registers MOV R1, #34 ; set R1 to 34 MOV R2, #54 ; set R2 to 54 MOV R3, #21 ; set R3 to 21 MOV R0, #0 ; set R0 to 0 (this will hold our answer)
; compare the values in R1 and R2 CMP R1, R2 ; compare R1 and R2 BGE check_R1_R3 ; jump to check_R1_R3 if R1 >= R2 B check_R2_R3 ; jump to check_R2_R3 if R1 < R2
check_R1_R3: ; compare the values in R1 and R3 CMP R1, R3 ; compare R1 and R3 BGE set_R0_R1 ; if R1 >= R3, set R0 to R1 MOV R0, R3 ; otherwise, set R0 to R3 B end ; jump to end
check_R2_R3: ; compare the values in R2 and R3 CMP R2, R3 ; compare R2 and R3 BGE set_R0_R2 ; if R2 >= R3, set R0 to R2 MOV R0, R3 ; otherwise, set R0 to R3 B end ; jump to end
set_R0_R1: ; set R0 to the value in R1 MOV R0, R1 ; set R0 to R1 B end ; jump to end
set_R0_R2: ; set R0 to the value in R2 MOV R0, R2 ; set R0 to R2 B end ; jump to end
end: ; exit the program BX LR ; return from the function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
