Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns the character 'A' if n >= 90, 'B' if 90 > n >= 80, etc. (Use the ASCII code.)
C++ Code:
int grade(int n){
if(n>=90)
return 65
else if(n<90 && n>=80)
return 66
else if(n<80 && n>=70)
return 67
else if(n<70 && n>=60)
return 68
else if(n<60 && n>=50)
return 69
else
return 70
}
ARMv8 code:
grade(int):
sub sp, sp, #16
str w0, [sp, 12]
ldr w0, [sp, 12]
cmp w0, 89
ble .L2
mov w0, 65
b .L3
.L2:
ldr w0, [sp, 12]
cmp w0, 89
bgt .L4
ldr w0, [sp, 12]
cmp w0, 79
ble .L4
mov w0, 66
b .L3
.L4:
ldr w0, [sp, 12]
cmp w0, 79
bgt .L5
ldr w0, [sp, 12]
cmp w0, 69
ble .L5
mov w0, 67
b .L3
.L5:
ldr w0, [sp, 12]
cmp w0, 69
bgt .L6
ldr w0, [sp, 12]
cmp w0, 59
ble .L6
mov w0, 68
b .L3
.L6:
ldr w0, [sp, 12]
cmp w0, 59
bgt .L7
ldr w0, [sp, 12]
cmp w0, 49
ble .L7
mov w0, 69
b .L3
.L7:
mov w0, 70
.L3:
add sp, sp, 16
ret
if you like the answer please provide a thumbs up.
Get Answers For Free
Most questions answered within 1 hours.