November 2nd, 2009, 06:13 AM

Max min from array
Write a program in Assembly Language to find the maximum number and the minimum number from an array of ten positive numbers. Store the minimum number in AX and maximum number in DX.
[Hint: Use the conditional jumps]
I have this C++ code, I need to convert it to assembly language, please help me!
main ()
{
int i;
int a[10] = { 10, 55, 9, 4, 234, 20, 30, 40, 22, 34 };
int max = a[0];
int min = a[0];
for (i = 0; i < 10; i++)
{
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
printf ("Maximum element in an array : %d\n", max);
printf ("Minimum element in an array : %d\n", min);
return 0;
}

November 16th, 2009, 05:26 AM

Originally Posted by Missy888
Write a program in Assembly Language to find the maximum number and the minimum number from an array of ten positive numbers. Store the minimum number in AX and maximum number in DX.
[Hint: Use the conditional jumps]
I have this C++ code, I need to convert it to assembly language, please help me!
main ()
{
int i;
int a[10] = { 10, 55, 9, 4, 234, 20, 30, 40, 22, 34 };
int max = a[0];
int min = a[0];
for (i = 0; i < 10; i++)
{
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
printf ("Maximum element in an array : %d\n", max);
printf ("Minimum element in an array : %d\n", min);
return 0;
}

If you need to do simple things in assembly like that then you can rely on basic fundamentals.
So to check min or max what would do in terms of math? In my head if I want to know if 10 is higher then 8 then I work out the difference.
108=2 there's a positive remainder so so 10 is higher.
Ofcourse most assemblers have things such as conditional jumps or you could do it on your on with sub and checking the sign flag.
You could just print out the assembly from your C compiler for your C code and look at how it produced it.