Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 2nd, 2009, 06:13 AM
 Missy888
Registered User

Join Date: Nov 2009
Posts: 1
Time spent in forums: 10 m 55 sec
Reputation Power: 0
Assembly - 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]

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;
}

-----------------------

#2
November 16th, 2009, 05:26 AM
 Sysop_fb
Registered User

Join Date: Mar 2005
Posts: 20
Time spent in forums: 15 h 12 m 18 sec
Reputation Power: 0
Quote:
 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.
10-8=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.

 Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Assembly - Max min from array