We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

smartrider
smartrider asked
on
Medium Priority
651 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.
Comment
Watch Question

Commented:

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

Commented:
you need to decrement ecx and check your zero flag
so that you don't stay in the loop for ever

Author

Commented:
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!

Commented:
@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

Commented:
sorry, is loop an assembly command?  I have never seen it in machine ops

Commented:
Yes, LOOP is an 80x86 opcode.  Also LOOPE, LOOPNE, etc.

Author

Commented:
Can this code be used in ARC program ?

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

What is 'ARC program' ?
Sorry, this is kind of a smart-alecky answer, but how about this:

    mov eax, -7

No loops, no fuss, no muss!

Author

Commented:
It is a tool called the ARC simulator . Check out this website :

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

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.