Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert this C Code to an ARMv8 Assembly Code program: #include float voltage, p

ID: 3866014 • Letter: C

Question

Convert this C Code to an ARMv8 Assembly Code program:

#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

Here is the conversion of C Code to an ARMv8 Assembly Code program:

voltage:

.zero 4

power:

.zero 4

.LC0:

.string "Enter the current value:"

.LC1:

.string "%f"

.LC2:

.string "Enter the value of Resistance:"

main:

stp x29, x30, [sp, -32]!

add x29, sp, 0

adrp x0, .LC0

add x0, x0, :lo12:.LC0

bl printf

add x1, x29, 28

adrp x0, .LC1

add x0, x0, :lo12:.LC1

bl scanf

adrp x0, .LC2

add x0, x0, :lo12:.LC2

bl printf

add x1, x29, 24

adrp x0, .LC1

add x0, x0, :lo12:.LC1

bl scanf

ldr s0, [x29, 28]

ldr s1, [x29, 24]

bl findvoltage(float, float)

ldr s0, [x29, 28]

adrp x0, voltage

add x0, x0, :lo12:voltage

ldr s1, [x0]

bl findcurrent(float, float)

mov w0, 0

ldp x29, x30, [sp], 32

ret

.LC3:

.string "voltage is %2f: "

findvoltage(float, float):

stp x29, x30, [sp, -32]!

add x29, sp, 0

str s0, [x29, 28]

str s1, [x29, 24]

ldr s1, [x29, 28]

ldr s0, [x29, 24]

fmul s0, s1, s0

adrp x0, voltage

add x0, x0, :lo12:voltage

str s0, [x0]

adrp x0, voltage

add x0, x0, :lo12:voltage

ldr s0, [x0]

fcvt d0, s0

adrp x0, .LC3

add x0, x0, :lo12:.LC3

bl printf

nop

ldp x29, x30, [sp], 32

ret

.LC4:

.string "power is %2f:"

findcurrent(float, float):

stp x29, x30, [sp, -32]!

add x29, sp, 0

str s0, [x29, 28]

str s1, [x29, 24]

ldr s1, [x29, 28]

ldr s0, [x29, 24]

fmul s0, s1, s0

adrp x0, power

add x0, x0, :lo12:power

str s0, [x0]

adrp x0, power

add x0, x0, :lo12:power

ldr s0, [x0]

fcvt d0, s0

adrp x0, .LC4

add x0, x0, :lo12:.LC4

bl printf

nop

ldp x29, x30, [sp], 32

ret