Convert this C Code to an ARMv8 Assembly Code program in gcc 5.4 or above: #incl
ID: 3866052 • Letter: C
Question
Convert this C Code to an ARMv8 Assembly Code program in gcc 5.4 or above:
#include
float voltage, power;
void findvoltage(float,float);
void findcurrent(float,float);
main()
{
float current,resistance;
printf("Enter the Current value: ");
scanf("%f",¤t);
printf("Enter the value of Resistance: ");
scanf("%f",&resistance);
findvoltage(current,resistance);
findcurrent(current,voltage);
}
void findvoltage(float current,float resistance)
{
voltage=current*resistance;
printf("The Voltage is: %.2f ",voltage);
}
void findcurrent(float current,float voltage)
{
power=current*voltage;
printf("The Power is: %.2f ",power);
}
Explanation / Answer
voltage:
power:
t:
resistance:
.LC0:
.ascii "Enter the Current value: "
.LC1:
.ascii "%f"
.LC2:
.ascii "Enter the value of Resistance: "
main:
stmfd sp!, {fp, lr}
add fp, sp, #4
sub sp, sp, #8
ldr r0, .L3
bl printf
ldr r1, .L3+4
ldr r0, .L3+8
bl scanf
ldr r0, .L3+12
bl printf
sub r3, fp, #12
mov r1, r3
ldr r0, .L3+8
bl scanf
ldr r3, [fp, #-12] @ float
mov r1, r3
ldr r0, [fp, #-8] @ float
bl findvoltage(float, float)
ldr r3, .L3+16
ldr r3, [r3] @ float
mov r1, r3
ldr r0, [fp, #-8] @ float
bl findcurrent(float, float)
mov r3, #0
mov r0, r3
sub sp, fp, #4
ldmfd sp!, {fp, lr}
bx lr
.L3:
.word .LC0
.word t
.word .LC1
.word .LC2
.word voltage
.LC3:
.ascii "The Voltage is: %.2f "
findvoltage(float, float):
stmfd sp!, {r4, fp, lr}
add fp, sp, #8
sub sp, sp, #12
str r0, [fp, #-16] @ float
str r1, [fp, #-20] @ float
ldr r1, [fp, #-20] @ float
ldr r0, [fp, #-16] @ float
bl __aeabi_fmul
mov r3, r0
mov r2, r3
ldr r3, .L6
str r2, [r3] @ float
ldr r3, .L6
ldr r3, [r3] @ float
mov r0, r3
bl __aeabi_f2d
mov r3, r0
mov r4, r1
mov r2, r3
mov r3, r4
ldr r0, .L6+4
bl printf
mov r0, r0 @ nop
sub sp, fp, #8
ldmfd sp!, {r4, fp, lr}
bx lr
.L6:
.word voltage
.word .LC3
.LC4:
.ascii "The Power is: %.2f "
findcurrent(float, float):
stmfd sp!, {r4, fp, lr}
add fp, sp, #8
sub sp, sp, #12
str r0, [fp, #-16] @ float
str r1, [fp, #-20] @ float
ldr r1, [fp, #-20] @ float
ldr r0, [fp, #-16] @ float
bl __aeabi_fmul
mov r3, r0
mov r2, r3
ldr r3, .L9
str r2, [r3] @ float
ldr r3, .L9
ldr r3, [r3] @ float
mov r0, r3
bl __aeabi_f2d
mov r3, r0
mov r4, r1
mov r2, r3
mov r3, r4
ldr r0, .L9+4
bl printf
mov r0, r0 @ nop
sub sp, fp, #8
ldmfd sp!, {r4, fp, lr}
bx lr
.L9:
.word power
.word .LC4