Modify your code from the following code so that it it now has a “main” and a se
ID: 3861868 • Letter: M
Question
Modify your code from the following code so that it it now has a “main” and a separate function “largest” that take 3 parameters (r0, r1, r2) and returns the largest of the three in r4. The main will load these values from memory, call the function and then store the result back into memory.
As this function is a “leaf” function, and should only use R0-R3, it can be written more simply than recursive fibonacci as it will not need to save and restore values from the stack. So this function will be structured more like function2 than function1 from the example above.
this code to find the largest number from three given number (ARM Assembly language)
adr R0, large
MOV R5, #4
ldr R1, [R0], #4
ldr R2, [R0], #4
ldr R3, [R0], #4
MOV R4, #0
CMP R1, R2
BMI Big
B Big2
Big CMP R2, R3
BMI Big3
B Big4
Big2 CMP R1, R3
BMI Big5
MOV R4, R1
ldr R0, =setlarge
str R4, [R0], #4
END
Big4 MOV R4, R2
ldr R0, =setlarge
str R4, [R0], #4
END
Big3 MOV R4,R3
ldr R0, =setlarge
str R4, [R0], #4
END
Big5 MOV R4,R3
ldr R0, =setlarge
str R4, [R0], #4
large DCD 34,54,21
setlarge DCD 0
END
Explanation / Answer
mMov R5,#4
Idr R1,[Ro],#4
Idr R2,[Ro],#4
Idr R3,[Ro],#4
LRGT R ?
ENDS
Code segment
Assume DS:Data CS:Code
Start:
MOV AX,DATA
MOV DS,AX
MOV AL,NUM1
MOV LGRT,AL
COM AL,NUM2
JGE SKIP1
MOV AL,NUM2
MOV LGRT ,AL
SKIP1
MOV AL,LGRT
CMP AL,NUM3
JGE SKIP2
MOV AL ,NUM3
MOV LGRT,AL
SKIP 2:
MOV AH,4CH
INT 21H
ENDS ENDS START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.