Convert this C Code to an ARMv8 Assembly Code program in gcc 5.4 or above: #incl
ID: 3866055 • 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:
.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, #16
ldr r0, .L3
bl printf
sub r3, fp, #16
mov r1, r3
ldr r0, .L3+4
bl scanf
ldr r0, .L3+8
bl printf
sub r3, fp, #12
mov r1, r3
ldr r0, .L3+4
bl scanf
vldr.32 s15, [fp, #-12]
vmov.f32 s1, s15
vldr.32 s0, [fp, #-8]
bl findvoltage(float, float)
ldr r3, .L3+12
vldr.32 s15, [r3]
vmov.f32 s1, s15
vldr.32 s0, [fp, #-8]
bl findcurrent(float, float)
mov r3, #0
mov r0, r3
sub sp, fp, #4
ldmfd sp!, {fp, lr}
bx lr
.L3:
.word .LC0
.word .LC1
.word .LC2
.word voltage
.LC3:
.ascii "The Voltage is: %.2f
"
findvoltage(float, float):
stmfd sp!, {fp, lr}
add fp, sp, #4
sub sp, sp, #8
vstr.32 s0, [fp, #-8]
vstr.32 s1, [fp, #-12]
vldr.32 s14, [fp, #-8]
vldr.32 s15, [fp, #-12]
vmul.f32 s15, s14, s15
ldr r3, .L6
vstr.32 s15, [r3]
ldr r3, .L6
vldr.32 s15, [r3]
vcvt.f64.f32 d7, s15
vmov r2, r3, d7
ldr r0, .L6+4
bl printf
mov r0, r0 @ nop
sub sp, fp, #4
ldmfd sp!, {fp, lr}
bx lr
.L6:
.word voltage
.word .LC3
.LC4:
.ascii "The Power is: %.2f
"
findcurrent(float, float):
stmfd sp!, {fp, lr}
add fp, sp, #4
sub sp, sp, #8
vstr.32 s0, [fp, #-8]
vstr.32 s1, [fp, #-12]
vldr.32 s14, [fp, #-8]
vldr.32 s15, [fp, #-12]
vmul.f32 s15, s14, s15
ldr r3, .L9
vstr.32 s15, [r3]
ldr r3, .L9
vldr.32 s15, [r3]
vcvt.f64.f32 d7, s15
vmov r2, r3, d7
ldr r0, .L9+4
bl printf
mov r0, r0 @ nop
sub sp, fp, #4
ldmfd sp!, {fp, lr}
bx lr
.L9:
.word power
.word .LC4
-----------------------------
NOTE: This assembly code is generated by converting the above C code into ARM assembly using gcc 5.4