flat assembler
Message board for the users of flat assembler.

 Index > Main > HELP: swaping between 3 array (fast routine)?
Author
xspeed

Joined: 16 Aug 2007
Posts: 22
xspeed 16 Aug 2007, 14:59
hey here is the problem i am trying to swap three array around like this

array 1=a1[]=0 to 1000000 elements, containing number from 0 to 255
array 2=a2[]=0 to 255 elements, containing random numbers
array 3=a3[]=0 to 1000000 elements,contain no number
count=1000000*4

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for

basic asm routine

long1 equ[esp+4] ;location of a1[0]
long2 equ[esp+8] ;location of a2[0]
long3 equ[esp+16];location of a3[0]
long4 equ[esp+20];location of count
mov ecx,0
loopme:
mov eax,long1
mov eax,dword ptr [eax] ;eax contain a1[ecx\4];ecx=ecx+4
lea eax,[eax*4]
mov ebx,long2
mov ebx,dword ptr [ebx];ebx contain a2[a1[ecx\4]]
mov eax,long3
mov dword ptr [eax],ebx
mov ebx,long4
mov ebx,[ebx]
cmp ecx,ebx
je loopme
ret 8
16 Aug 2007, 14:59
DOS386

Joined: 08 Dec 2006
Posts: 1900
DOS386 16 Aug 2007, 21:10
Code:
```array 1=a1[]=0 to 1000000 elements, containing number from 0 to 255
array 2=a2[]=0 to 255 elements, containing random numbers
array 3=a3[]=0 to 1000000 elements,contain no number
count=1000000*4

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for

Very ^^^ odd "BASIC" ;

FASM code:

mov esi,a1
mov ebx,a2
mov edi,a3

xor eax,eax       ; MOV EAX,0
mov ecx,1000000   ; 1 M decimal or 999'999 only

@@: mov  al,[esi+ecx]
mov  al,[ebx+eax]
mov  [edi+ecx],al
loop  @b
```

Note:

dword ptr is crap and has been banned from FASM

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
16 Aug 2007, 21:10
f0dder

Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 16 Aug 2007, 22:56
NTOSKRNL_VXE wrote:
dword ptr is crap and has been banned from FASM

Not really, in fasm it's just called "dword". And in the code snippet by the original poster, it wasn't necessary, not even for MASM, since the data size with register use is implicit.

_________________
- carpe noctem
16 Aug 2007, 22:56
xspeed

Joined: 16 Aug 2007
Posts: 22
xspeed 17 Aug 2007, 16:56
hey thank

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for

Very ^^^ odd "BASIC" ;

^^^ maple v9.5 a math program with programming language

basic:
for n=0 to 100000
a3[n]=a2[a1[n]]
next

i hooked fasm to maple 9.5

my routine take about 75->90 tickcount for one run

8749 tickcount for 100

for i from 0 to 99 by 1 do
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end do
end do

too slow

874 ticket for 100 would be nice
874 ticket for 1000 would be really nice

something like the basic routine for transferring a2[n]=a1[n] with rep movsb
17 Aug 2007, 16:56
DOS386

Joined: 08 Dec 2006
Posts: 1900
DOS386 18 Aug 2007, 05:24
> my routine take about 75->90 tickcount

Tested mine ?

> something like the basic routine for transferring a2[n]=a1[n] with rep movsb

SORRY but MOVSx doesn't index via a 3rd array ... just post a feature request for SSSSSE 5
18 Aug 2007, 05:24
Mac2004

Joined: 15 Dec 2003
Posts: 314
Mac2004 18 Aug 2007, 07:06
xspeed: Could you please use code tags? Your code is much more readable that way...

regards,
Mac2004
18 Aug 2007, 07:06
xspeed

Joined: 16 Aug 2007
Posts: 22
xspeed 20 Aug 2007, 14:32
NTOSKRNL_VXE=60->70 tickcount*100 times=6547
tickcount=GetTickCount in kernel32.lib/dll

6547=6.547 sec

can you reduce it down to .654 sec for 100 times with 1000001 long value elements=4000004 bytes?
20 Aug 2007, 14:32
Plue

Joined: 15 Dec 2005
Posts: 151
Plue 20 Aug 2007, 19:56
The elements are all dword sized, right?

Edit:
This is my fastest yet:
Code:
```  mov eax, [v_a] ; eax <- address of a[0]
mov ebx, [v_b] ; ebx <- address of b[0]
mov ecx, [v_c] ; ecx <- address of c[0]

mov edx, 100000*4 ; edx <- counter

lp:
sub edx, 4
mov esi, [eax+edx]
mov esi, [ebx+esi]
mov [ecx+edx], esi
jnz lp    ```

You can probably get it much faster by changing the algorithm a bit. What do you need it for?
20 Aug 2007, 19:56
xspeed

Joined: 16 Aug 2007
Posts: 22
xspeed 23 Aug 2007, 16:07
direct swapping them would be the fastest but i dont know how

anyone have a clue on how to swap them faster?

plue: for a new encode/media format file
23 Aug 2007, 16:07
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum