flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
SolidThink
hello, i'm newbie
i would make an experiment i have this : http://www.algorithmist.com/index.php/Prime_Sieve_of_Eratosthenes.c it possible convert this in fasm for see time and efficent differences ? some good soul help me ? TY |
|||
![]() |
|
revolution
|
|||
![]() |
|
SolidThink
revolution wrote: Maybe this can help you to get started. thanks for the link, but i would use the same c algo of my link for run equivalent code on c and asm, i want to see how much time takes ASM and how much time takes C with the same type of code, shure ASM is more fast , but how much time is more fast ? ![]() i have compiled the c, report : Code: The number of primes below 10^8 is 5761455. Process returned 0 (0x0) execution time : 0.790 s Press any key to continue. |
|||
![]() |
|
bitRAKE
I use the binary prime sieve sometimes. Although it is very fast to generate, memory access will bring both implementations towards similar timing. Where the assembly version might benefit is in accessing the binary array after generation - a single instruction.
Try the Sieve of Atkin for faster results. |
|||
![]() |
|
Plue
That is a ridiculously unreadbly written C code.
|
|||
![]() |
|
SolidThink
Plue wrote: That is a ridiculously unreadbly written C code. I can ask why? |
|||
![]() |
|
bitRAKE
<Rant>
Code: void make() { uint32_t i, j, k; memset(sieve, 0, sizeof(sieve)); for (k = 1; k <= P3; k++) if (GET(k)==0) for(j=2*k+1,i=2*k*(k+1);i<P2;i+=j) sieve[i>>5]|=1<<(i&31); } int isprime(int p) { return p==2 || (p>2 && (p&1)==1 && (GET((p-1)>>1)==0)); } Imagine someone is used to looking at: Code: @@: mov eax,1 mov ecx,edx and ecx,11111b shl eax,cl mov ecx,edx shr ecx,5 or [edi+ecx*4],eax add edx,ebx cmp edx,P2 jc @B The same can be said for assembly language programmers which use the full instruction set. In fact I dread reading some assembly code where the author only knows a dozen instructions. So, artistically it adds flavor and style, or might even say something about the author. Except it was presented on a web page for a wider audience. ![]() </Rant> BTW, the inner loop could be reduced to: (The compiler isn't capable of the reduction.) Code: @@: bts [edi],edx add edx,ebx cmp edx,P2 jc @B ![]() |
|||
![]() |
|
SolidThink
bitRAKE wrote: <Rant> I've rewritten the code ![]() Code: #include <stdio.h> #include <math.h> #include <time.h> #include <string.h> unsigned int PRME_01=2000000; unsigned int num_01,sel_01,numofprim_01=0,numprim_01=0; #define DIVPRM sqrt(PRME_01) int main() { char nprime_01[PRME_01+1]; memset(nprime_01,1,PRME_01); nprime_01[0]=0; nprime_01[1]=0; int timea; timea=clock(); for (num_01=2;num_01<=DIVPRM;num_01++) { if (nprime_01[num_01]) { for (sel_01=2;sel_01<=(PRME_01/num_01);sel_01++) { nprime_01[sel_01*num_01]=0;}}} printf("\nPrimes between 2 and 2.000.000 = ", PRME_01 ); for (num_01=2;num_01<=PRME_01;num_01++) if (nprime_01[num_01]) ++numofprim_01; timea=clock()-timea; printf("%ld \n \nMilliseconds Elapsed = %d\n\n", numofprim_01, timea); system("PAUSE"); return (0); } Code: Primes between 2 and 2.000.000 = 148933 Milliseconds Elapsed = 7 |
|||
![]() |
|
bitRAKE
Oh, that is funny.
![]() |
|||
![]() |
|
SolidThink
bitRAKE wrote: Oh, that is funny. C i'm bit capable, but ..asm ... i do pity ![]() ![]() |
|||
![]() |
|
vid
What's the point of rewriting same algorithm in ASM, when ASM has features for much more effective way?
Is it just another "Me vs. C optimizer" contest? |
|||
![]() |
|
SolidThink
vid wrote: What's the point of rewriting same algorithm in ASM, when ASM has features for much more effective way? Code: #include <stdio.h> #include <math.h> #include <time.h> #include <string.h> #include <windows.h> unsigned int PRME_01=2000000,num_01,sel_01,numofprim_01=0,numprim_01=0; #define DIVPRM sqrt(PRME_01) int main(){ char nprime_01[PRME_01+1]; memset(nprime_01,1,PRME_01); nprime_01[0]=nprime_01[1]=0; unsigned int timea=clock(); num_01=2; while(num_01<=DIVPRM){ if(nprime_01[num_01]){ sel_01=2; while(sel_01<=(PRME_01/num_01)){ nprime_01[sel_01*num_01]=0; sel_01++; }} num_01++; } printf("\nPrimes between 2 and 2.000.000 = ", PRME_01 ); num_01=2; while(num_01<=PRME_01){ if(nprime_01[num_01]) ++numofprim_01; num_01++; } timea=clock()-timea; printf("%ld \n \nMilliseconds Elapsed = %d\n\n", numofprim_01, timea); system("PAUSE"); return (0); } a bit optimizations of precedent code; I want to learn asm, if i see the asm code and compare it with this C code, that i know well, i think understand better how start and where make mistakes... ![]() and i also like to see the execution time, i'll admit... |
|||
![]() |
|
Borsuc
Have you ever heard of WHITESPACE? Aligning the C Code for readability under columns? I find it very cryptic as well.
|
|||
![]() |
|
baldr
|
|||
![]() |
|
vid
SolidThink wrote:
To learn ASM, I would suggest to start with something simpler, and trace your code in debugger (OllyDbg). That way you learn faster than with comparing ASM code to C code. Or, just compile your code and look at it in asm dump and dissasembler. |
|||
![]() |
|
baldr
vid wrote: Or, just compile your code and look at it in asm dump and dissasembler. ![]() |
|||
![]() |
|
SolidThink
thank you very ... math ...
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.