Solved

Assembly Code to find a minimum of a set of 5 signed 32 bit integers?

Posted on 2004-04-07
11
567 Views
Last Modified: 2010-05-18
I am new to assembly coding. I am trying to write an assembly code that will find the minumum of set of 5 signed 32 bit integers.
The data is - 1,-7,6,8,9

Can someone please help me out.
0
Comment
Question by:smartrider
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:mblais1
ID: 10775273

values  sdword  - 1,-7,6,8,9  ; signed 32-bit numbers

       mov    ebx, offset values ; EBX points to the array of 5 ints.
       mov    ecx, 5                 ; how many numbers in the array
       mov    eax, 07FFFFFFFh ; Holds current minimum value found
L1:  mov    edx, [ebx+ecx*4] ; get next number in list
       cmp    eax, edx
       jle      L2
       mov    eax, edx             ; found new minimum value
L2:  loop    L1

; Minimum value from array is now in EAX
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10775530
you need to decrement ecx and check your zero flag
so that you don't stay in the loop for ever
0
 

Author Comment

by:smartrider
ID: 10775539
thanks for the reply mblias1. Can you please explain me something :

don't we need to add "len= 20" since there are 5 values in the array ?. According to my task - it states that save the minimum value into memory name "Northwest" and the "Greg" is the location name for the first array element.

Please assist.

I appreciate your help!
0
 
LVL 1

Expert Comment

by:mblais1
ID: 10775652
@Kavar: the LOOP instruction means "decrement ECX and branch if nonzero."

@smartrider: substitute 'Greg' for 'values' in the code above,  and add the following instruction at the end:
      mov   [Northwest], eax

you'll also need to define Northwest somewhere, maybe like this at the top:

Northwest  sdword  0
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10776209
sorry, is loop an assembly command?  I have never seen it in machine ops
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:mblais1
ID: 10776269
Yes, LOOP is an 80x86 opcode.  Also LOOPE, LOOPNE, etc.
0
 

Author Comment

by:smartrider
ID: 10777484
Can this code be used in ARC program ?
0
 
LVL 1

Expert Comment

by:mblais1
ID: 10777573
This is 80x86 assembly language, which can be used with any 80x86 assembler (e.g., MASM, or MSVC).

What is 'ARC program' ?
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 10777611
Sorry, this is kind of a smart-alecky answer, but how about this:

    mov eax, -7

No loops, no fuss, no muss!
0
 

Author Comment

by:smartrider
ID: 10777620
It is a tool called the ARC simulator . Check out this website :

http://paul.rutgers.edu/~weiz/cs211spring03/archelp.html

0
 
LVL 1

Accepted Solution

by:
mblais1 earned 500 total points
ID: 10777678
That page does not say what language ARC simulator uses, so I could not tell you if it is compatible with 80x86 code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now