Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 08-10-2004, 06:21 AM   #1 (permalink)
Junkie
 
nukeu666's Avatar
 
Location: India
[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..
nukeu666 is offline  
Old 08-10-2004, 05:28 PM   #2 (permalink)
I am Winter Born
 
Pragma's Avatar
 
Location: Alexandria, VA
If you're trying to exchange two values, the best way to do that is three XOR operations.

xorl %eax, %edx
xorl %ebx, %eax
xorl %eax, %edx

However, the thing to pay attention to is the list of legal operands:
src dst
idata reg
idata mem
reg reg
mem reg
reg mem

So I think what you'd have to do is move both pieces of data from the array to registers, XOR them, then move them back.

However, now that I put more thought into it, that might not answer your solution. I'll give it some more thought.
__________________
Eat antimatter, Posleen-boy!
Pragma is offline  
Old 08-11-2004, 04:02 AM   #3 (permalink)
Junkie
 
nukeu666's Avatar
 
Location: India
my program finally ran...why..i dunno
maybe coz of compiler/OS/processor version quirks
__________________
Why did the Comp. Engineer get X-mas and Halloween mixed up?
Because Oct(31) == Dec(25)
nukeu666 is offline  
 

Tags
asm, divide, integers


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 10:25 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62