I have the following in C, which btw I don't write in but need to translate..

int minx = min(0,min(x1, min(x2,x3)));

and have translated it as follows:

	mov eax,[x1]

cmp eax,[x2]
jl >
mov eax,[x2]
:
cmp eax,[x3]
jl >
mov eax,[x3]
:
cmp eax,0
jl >
mov eax,0
:
mov [minx],eax


is this right ?
Posted on 2004-08-04 16:02:24 by donkey
I would work from inside the parenthesis on out..

compare x2,x3 first
then x1 to result of x2,x3
then finally 0 to result
Posted on 2004-08-04 16:10:49 by drarem
For min I would have assumed that it could not make a difference, it is to find the smallest of 3 variables and 0, what I need to know mostly is if it is a signed comparison or not.
Posted on 2004-08-04 16:15:37 by donkey
Doh, makes sense.. I'm just a cold logical person..

INT is signed..

to have it unsigned it must be declared: UNSIGNED INT minx;

here are some C/C++ datatypes:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/reftable_1.asp

and why do I have to log in every 5 minutes to post something.. is it my browser settings or this forum, I don't seem to have trouble with other sites.
Posted on 2004-08-04 16:22:37 by drarem
Thanks drarem,

That's what I needed to know, so it is a valid translation. You know you can always tell a C algorithm translated to assembly, there are a ton of LOCALs. C programmers seem to have the habit of declaring a variable for everything and it's dog. The pain is that 90% are declared inline so the LOCAL block just grows and grows as you move through the function. This one is 300+ lines of C and so far has around 50 LOCALs declared, that will drop down as I get rid of the useless ones.
Posted on 2004-08-04 16:32:38 by donkey
I generally assume that min() is implemented as a macro. That means the operand types determine whether it's a signed or unsigned compare. The function is not part of the C or C++ standard library, so I end up having to write a macro for it when I'm coding in non-Windows mode.

If I remember correctly, signed can be promoted to unsigned, so a comparison with an unsigned value is always an unsigned compare.
Posted on 2004-08-04 18:21:39 by tenkey
In MASM, with the HLL directives, a macro can be created for the general case. Then the type can be passed to the macro -- only the jump instruction changes during assemble-time. Unsigned instructions operate on the carry flag, whereas signed instructions operate on sign & overflow flags - the zero flag is used by both.
Posted on 2004-08-04 18:39:00 by bitRAKE
The C++ standard library does define a min() function template.
Posted on 2004-08-04 18:40:27 by death