
Patrick B. answered 08/19/21
Math and computer tutor/teacher
#include <stdio.h>
#include <stdlib.h>
void Go(double * source, double * sink, int nSize, double incrAmt, double * minVal)
{
int iLoop;
*minVal = source[0];
for (iLoop=0; iLoop<nSize; iLoop++)
{
sink[iLoop] = source[iLoop]+incrAmt;
if (source[iLoop]<*minVal)
{
*minVal = source[iLoop];
}
}
}
int main()
{
double A[] = {35.42, 2.723, 42.35, 3.1415926, 7.11, 7.24, 7.25, 13.59, 24.36, 36.32};
double* a;
int N=10;
double deltaX=5.0f;
double minVal;
int iLoop;
a = (double*)malloc(N*sizeof(double));
Go(A,a,N,deltaX,&minVal);
for (iLoop=0; iLoop<N; iLoop++)
{
printf("%8.6lf \n",a[iLoop]);
}
printf(" the min is %6.2f \n",minVal);
free(a);
}
/*******************************************************************************/
'*****************************************************************************
Go:
push {r11, lr}
mov r11, sp
sub sp, sp, #40
ldr r3, [r11, #12]
ldr r12, [r11, #8]
ldr lr, [r11, #16]
str r0, [r11, #-4]
str r1, [r11, #-8]
str r2, [r11, #-12]
str r3, [sp, #20]
str r12, [sp, #16]
ldr r0, [r11, #-4]
ldr r1, [r0]
ldr r0, [r0, #4]
ldr r2, [r11, #16]
str r0, [r2, #4]
str r1, [r2]
mov r0, #0
str r0, [sp, #12]
b .LBB0_1
.LBB0_1: @ =>This Inner Loop Header: Depth=1
ldr r0, [sp, #12]
ldr r1, [r11, #-12]
cmp r0, r1
bge .LBB0_6
b .LBB0_2
.LBB0_2: @ in Loop: Header=BB0_1 Depth=1
ldr r0, [r11, #-4]
ldr r1, [sp, #12]
ldr r2, [r0, r1, lsl #3]!
ldr r0, [r0, #4]
ldr r3, [sp, #16]
ldr r12, [sp, #20]
str r0, [sp, #8] @ 4-byte Spill
mov r0, r2
ldr r2, [sp, #8] @ 4-byte Reload
str r1, [sp, #4] @ 4-byte Spill
mov r1, r2
mov r2, r3
mov r3, r12
bl __aeabi_dadd
ldr r2, [r11, #-8]
ldr r3, [sp, #4] @ 4-byte Reload
str r0, [r2, r3, lsl #3]!
str r1, [r2, #4]
ldr r0, [r11, #-4]
ldr r1, [sp, #12]
ldr r1, [r0, r1, lsl #3]!
ldr r0, [r0, #4]
ldr r2, [r11, #16]
ldr r12, [r2]
ldr r3, [r2, #4]
str r0, [sp] @ 4-byte Spill
mov r0, r1
ldr r1, [sp] @ 4-byte Reload
mov r2, r12
bl __aeabi_dcmplt
cmp r0, #0
beq .LBB0_4
b .LBB0_3
.LBB0_3: @ in Loop: Header=BB0_1 Depth=1
ldr r0, [r11, #-4]
ldr r1, [sp, #12]
ldr r1, [r0, r1, lsl #3]!
ldr r0, [r0, #4]
ldr r2, [r11, #16]
str r0, [r2, #4]
str r1, [r2]
b .LBB0_4
.LBB0_4: @ in Loop: Header=BB0_1 Depth=1
b .LBB0_5
.LBB0_5: @ in Loop: Header=BB0_1 Depth=1
ldr r0, [sp, #12]
add r0, r0, #1
str r0, [sp, #12]
b .LBB0_1
.LBB0_6:
mov sp, r11
pop {r11, lr}
bx lr
main:
push {r11, lr}
mov r11, sp
sub sp, sp, #144
mov r0, #0
str r0, [r11, #-4]
ldr r1, .LCPI1_0
add r2, sp, #56
mov r3, #80
str r0, [sp, #24] @ 4-byte Spill
mov r0, r2
str r2, [sp, #20] @ 4-byte Spill
mov r2, r3
bl memcpy
mov r1, #10
str r1, [sp, #48]
mov r1, #1310720
orr r1, r1, #1073741824
str r1, [sp, #44]
ldr r1, [sp, #24] @ 4-byte Reload
str r1, [sp, #40]
ldr r2, [sp, #48]
lsl r2, r2, #3
str r0, [sp, #16] @ 4-byte Spill
mov r0, r2
bl malloc
str r0, [sp, #52]
ldr r1, [sp, #52]
ldr r2, [sp, #48]
ldr r0, [sp, #40]
ldr r3, [sp, #44]
mov r12, sp
add lr, sp, #32
str lr, [r12, #8]
str r3, [r12, #4]
str r0, [r12]
ldr r0, [sp, #20] @ 4-byte Reload
bl Go
ldr r0, [sp, #24] @ 4-byte Reload
str r0, [sp, #28]
b .LBB1_1
.LBB1_1: @ =>This Inner Loop Header: Depth=1
ldr r0, [sp, #28]
ldr r1, [sp, #48]
cmp r0, r1
bge .LBB1_4
b .LBB1_2
.LBB1_2: @ in Loop: Header=BB1_1 Depth=1
ldr r0, [sp, #52]
ldr r1, [sp, #28]
ldr r2, [r0, r1, lsl #3]!
ldr r3, [r0, #4]
ldr r0, .LCPI1_2
bl printf
b .LBB1_3
.LBB1_3: @ in Loop: Header=BB1_1 Depth=1
ldr r0, [sp, #28]
add r0, r0, #1
str r0, [sp, #28]
b .LBB1_1
.LBB1_4:
ldr r2, [sp, #32]
ldr r3, [sp, #36]
ldr r0, .LCPI1_1
bl printf
ldr r1, [sp, #52]
str r0, [sp, #12] @ 4-byte Spill
mov r0, r1
bl free
ldr r0, [r11, #-4]
mov sp, r11
pop {r11, lr}
bx lr
.LCPI1_0:
.long .L__const.main.A
.LCPI1_1:
.long .L.str.1
.LCPI1_2:
.long .L.str
.L__const.main.A:
.long 2405181686 @ double 35.420000000000002
.long 1078048194
.long 962072674 @ double 2.7229999999999999
.long 1074120884
.long 3435973837 @ double 42.350000000000001
.long 1078275276
.long 1293080650 @ double 3.1415926000000001
.long 1074340347
.long 3607772529 @ double 7.1100000000000003
.long 1075605667
.long 2405181686 @ double 7.2400000000000002
.long 1075639746
.long 0 @ double 7.25
.long 1075642368
.long 2061584302 @ double 13.59
.long 1076571668
.long 4123168604 @ double 24.359999999999999
.long 1077435432
.long 3264175145 @ double 36.32
.long 1078077685
.L.str:
.asciz "%8.6lf \n"
.L.str.1:
.asciz " the min is %6.2f \n"