I'm new to Assembly so please bear with me! As the C program says I'm taking an array and the number of elements as parameters and passing the array and the number of elements to minmax. But my second task is to convert it to Assembly which has been a hassle.
#include <stdio.h>
void minmax(unsigned int ary[], int len)
{
int min = len, max = 0;
for(int i = 0; i < len; i++)
{
if(ary[i] < min)
{
min = ary[i];
}
if (ary[i] > max)
{
max = ary[i];
}
}
printf("min: %d max: %d\n", min, max);
}
int main()
{
static unsigned int ary[] = {4, 3, 2, 5, 6, 2, 3, 7, 8, 3};
const unsigned int ary_size = sizeof(ary) / sizeof(unsigned int);
minmax(ary, ary_size);
return 0;
}
And here is my assembly conversion that I've tried. I can't seem to load and initialize my min max and let the min equal the len in assembly. Please point out some hints on these instructions
.begin
.org 2048
a_start .equ 3000
array_size .equ 10
or %r0, 0, %r1
ld [len], %r1
ld [min], %r2
ld [max], %r3
forloop:
cmp %r1, array_size
bge endforloop
ld %r8, [a], %r2
cmp %r3, min
do next
ld %r11, [a]
move min, [a]
cmp %r3, max
do next
ld %r11, [a]
move max, [a]
endforloop:
halt
.org a_start
array: .dwb array_size
a: 4,3,2,5,6,2,3,7,8,3
.end
EDIT: Anyone help please? The assembly generated code isn't that helpful with all its scripts. I would prefer someone pointing out where I need to make changes for what reason. Many thanks!