I have the program in C im not sure how to transcribe it here is my c code: #inc
ID: 3866049 • Letter: I
Question
I have the program in C im not sure how to transcribe it
here is my c code:
#include<stdio.h>
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("voltage %f: ",voltage);
}
void findcurrent(float current,float voltage)
{
power=current*voltage;
printf("power is %f:",power);
}
2. Write a ARMv8 program that finds voltage drop and power dissipated by a resistance (R) when a current (I) flows through it. Resistance and current values are given as inputs. Create a function that would find the voltage drop, and create another function that would find the power. Use these functions in your program. The input and output values are single precision floating-point values. Assume the input resistance value (R) is in register SO and current (I) is in register S1. Store the computed voltage drop in register S2 and computed power in register S3. Assemble, test, and simulate the assembly code using DS-5 simulator. Do not upload the entire DS-5 project. OnlyExplanation / Answer
ARM gcc 5.4 code
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 %f: "
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 %f:"
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