[asm] exchange numbers in an array
im trying to make a prog in inline asm to find the median of an array of numbers
my last lines are
:"r="(median)
:"r"(size),"r"(n)
:"%eax"etcetc
so %2 is the addr of my array with 'size' elements
i want to sort the array and find the middle element
so im using bubble sort:
variables for bubble loop are i,j stored in eax,edx
mov 0(%2,%%eax,4),%%ebx #ebx=n[i]
mov 0(%2,%%edx,4),%%ecx #ecx=n[j]
if n[i]>n[j]
(i 1st tried)
xchg %%ebx,%%ecx ##this will only exchange values in ecx,ebx,not in the array
(then tried)
mov %%ebx,0(%2,%%edx,4) #n[j]=value of n[i] taken above
mov %%ecx,0(%2,%%eax,4) #similar
(but this didnt work either)
im taking the middle element like this:
mov %1,%%eax
sar $1,%%eax #divide eax by 2
mov 0(%2,%%eax,4),%0 #copy n[i/2] to median
if anyone understood what i asked, plz reply...
__________________
Why did the Comp. Engineer get X-mas and Halloween mixed up?
Because Oct(31) == Dec(25)
Last edited by nukeu666; 08-10-2004 at 09:16 AM..
|