Okay, here are a few other challenges:

1. You have three values: in. eax, ecx and edx. The goal is to put the minimum of those three in eax, and the maximum in ecx.
So if eax = 4, ecx=2 and edx=8, the output should be: eax = 2 (min) and ecx=8 (max).

2. Like 1 but with one input more (in ebx).

3. Like 1 but with floating point values:
``````
.data?
;in:
float1 real4 ?
float2 real4 ?
float3 real4 ?

;out:
minval real4 ?
maxval real4 ?
``````

4. like 3, but with one additional output: average real4 ? (right after maxval) which will hold the average of the three floating point values.

Happy coding!

Thomas
Posted on 2002-02-09 14:13:37 by Thomas
Well heres the FPU code for No.s 3 & 4
``````fld float1
fld float2
fld float3
fcomi st,st(1)
jb @F
fxch
@@:
fstp st(3)
fcomi st,st(1)
jb @F
fxch
@@:
fstp st(3)
fstp maxval
fcomi st,st(1)
ja @F
fxch
@@:
fstp st
fstp minval``````

``````fld float1
fst st(3)
fld float2
fld float3
fcomi st,st(1)
jb @F
fxch
@@:
fstp st(3)
fcomi st,st(1)
jb @F
fxch
@@:
fstp st(3)
fstp maxval
fcomi st,st(1)
ja @F
fxch
@@:
fstp st
fstp minval
fmul fpc(REAL8 0.33333333333333333333333)
fstp average``````

The now obvious offset addressing could be used to optimise the size of this. As for this being the fastest solution, well I doubt it. If you turn to Agner Fogs optimisation guide Ch. 27 he explains how to compare Real4 values in memory with the integer instructions which I'm sure would be faster.
Posted on 2002-02-09 18:50:23 by Eóin
``````
smallest MACRO Op1, OpX
irp Args, <OpX>
cmp Op1, &Args
jb  @f
push Op1
mov Op1, &Args
pop &Args
@@:
endm
ENDM

largest MACRO Op1, OpX
irp Args, <OpX>
cmp Op1, &Args
ja  @f
push Op1
mov Op1, &Args
pop &Args
@@:
endm
ENDM
``````

Answer #1: smallest eax, <ecx, edx>
largest ecx, <eax, edx>

Answer #2: smallest eax, <ebx, ecx, edx>
largest ecx, <eax, ebx, edx>

eax will contain the smallest value and
ecx will contain the largest value.
ebx/edx are not sorted.

You can remove the push/pop(I added it just in case you don't want to lose the original value that was changed - but in this problem you need 'em).

by the way, how come a lot of math and FPU tuts are coming out lately. Before, it was strings that was a hot topic now it's FPU and Math hmm..
Posted on 2002-02-09 20:52:52 by stryker
1.
mov esi,eax
cmova eax,ecx
cmovb ecx,esi
cmova eax,edx
cmovb ecx,edx
2.
mov esi,eax
cmova eax,ecx
cmovb ecx,esi
cmova eax,ebx
cmovb ecx,ebx
cmova eax,edx
cmovb ecx,edx
3.
fld
fld
fld
fld st
fcmovb st,st(2)
fcmovb st,st(3)
fstp
fcmovnbe st,st(1)
fcmovnbe st,st(2)
fstp
fcompp

4.
fld
fld
fld
fld st
fmul 0.3333333333333f
fstp
fld st
fcmovb st,st(2)
fcmovb st,st(3)
fstp
fcmovnbe st,st(1)
fcmovnbe st,st(2)
fstp
fcompp
ret

It's work?
Posted on 2002-02-10 14:42:08 by Nexo
.
mov esi,eax
cmp eax,ecx
cmova eax,ecx
cmp ecx,esu
cmovb ecx,esi
cmp eax,edx
cmova eax,edx
cmp ecx,edx
cmovb ecx,edx
2.
mov esi,eax
cmp eax,ecx
cmova eax,ecx
cmp ecx,esi
cmovb ecx,esi
cmp eax,ebx
cmova eax,ebx
cmp ecx,ebx
cmovb ecx,ebx
cmp eax,edx
cmova eax,edx
cmp ecx,edx
cmovb ecx,edx
3.
fld
fld
fld
fld st
fcomi st,st(2)
fcmovb st,st(2)
fcomi st,st(3)
fcmovb st,st(3)
fstp
fcomi st,st(1)
fcmovnbe st,st(1)
fcomi st,st(2)
fcmovnbe st,st(2)
fstp
fcompp

4.
fld
fld
fld
fld st
fmul 0.3333333333333f
fstp
fld st
fcomi st,st(2)
fcmovb st,st(2)
fcomi st,st(3)
fcmovb st,st(3)
fstp
fcomi st,st(1)
fcmovnbe st,st(1)
fcomi st,st(2)
fcmovnbe st,st(2)
fstp
fcompp
ret

or

fld
fld
fld
fld st
fmul 0.3333333333333f
fstp
movss xmm0,
movss xmm1,xmm0
maxss xmm0,
minss xmm1,
maxss xmm0,
minss xmm1,
movss ,xmm0
movss ,xmm1
ret
Posted on 2002-02-13 13:26:15 by Nexo
Nexo:
Wellcome to the contest :)
Thomas:
Could you, please, check all versions, test them and assign scores
to the winners?
Posted on 2002-02-13 15:12:30 by The Svin
I'll do that, but I wonder what the best test method would be. As the speed depends on the inputs I need to test it with multiple inputs so all the possible branche combinations will be tested.
What's the best way to set the values without influencing the actual test code?

Thomas
Posted on 2002-02-14 10:25:44 by Thomas
I'll do that, but I wonder what the best test method would be.

"That is the question" :)
Actually there even more questions, for example
what is target processor.
what opcodes allowed.
etc....
And I'm gratefull to you, Eyne and others who keep interest to
the subject alive.

As to me - now I think that I should start from 1st grade and
thinking how to start.
Positioned numeric system questions in depth and machine numeric format (complement 2 and IEEE) seems to me good topics to start, I wished to combine it with detail training on flag usage.
And I still need some basic math book in English.
It's to much to wait from me that I learn usall math expression
in command of English language by myself in short time, had I the
book - I could have gotten used to the commands much faster.

So many promisses but I still have no electrionic text book.
:)
People, I don't blame anybody, of course but it slowing me down to start :)
Posted on 2002-02-15 20:09:28 by The Svin