Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

gas anyone?

IDKIDK Posts: 1,784Member
[b][red]This message was edited by IDK at 2006-11-15 14:1:56[/red][/b][hr]
Anyone tried to use gas inlined assembly? I'm trying to do a simple SSE2 mandelbrot program with inline asm with Dev+C++.

[code]
int wid=256,heg=256;
#define wid 256
#define heg 256
GLubyte* buffer = new GLubyte[wid*heg];
int y=0;
GLubyte* p;

main(){
....
asm(".intel_syntax noprefix

//if(y==0) y=heg, pointer=buffer+wid*heg;

xor eax,eax

or eax,_y

jz initYP

returnInitYP:



mov ecx,_wid



mov _pointer,ebx

mov _y,eax

.att_syntax noprefix");
...
}
[/code]

That was the code calling the code I'm trying to write:
[code]
asm(".intel_syntax noprefix

initYP:

//y=heg, pointer=buffer+wid*heg;

mov eax,_heg

lea ebx,_pointer+256*256

jmp returnInitYP

.att_syntax noprefix");
[/code]

As you might see, wid and height in the lea statement are wierd.
Since gas cannot do any preprocesing and the manual:
http://sourceware.org/binutils/docs-2.17/as/index.html
suggests that I'll use the built in featurs of my C compiler.

How do I do that?

Anyone?

EDIT: Firefox crashed when I tried to post this...
I posted a workaround instead, but it still doesn't work for constants in the assembly, but almost...
Now it looks neater anyway.

I still have no clue...

Comments

  • Griz803Griz803 Posts: 100Member
    I think that the problem with this is that you're using Intel syntax (or trying to) with an assembler that uses AT&T syntax. Search the term 'AT&T assembler syntax' and you should get several references to tutorials. Also, check out this URL, http://heather.cs.ucdavis.edu/~matloff/50/LinuxAssembly.html#tth_sEc4
    It may help you out. Good luck.
  • IDKIDK Posts: 1,784Member
    : I think that the problem with this is that you're using Intel syntax (or trying to) with an assembler that uses AT&T syntax. Search the term 'AT&T assembler syntax' and you should get several references to tutorials. Also, check out this URL, http://heather.cs.ucdavis.edu/~matloff/50/LinuxAssembly.html#tth_sEc4
    : It may help you out. Good luck.
    :

    If you look at the start and at the end of each asm statement, you'll see that I first set the syntax to intel, and then I set it back to at&t

    That's even not the problem, if I had the wrong syntax the assembler would have given an error. The problem is that gas suggests me to use 'the C preproccessor' to as my preproccessor, but my cpp compiler won't do that.
  • netgertnetgert Posts: 331Member
    : [b][red]This message was edited by IDK at 2006-11-15 14:1:56[/red][/b][hr]
    : Anyone tried to use gas inlined assembly? I'm trying to do a simple SSE2 mandelbrot program with inline asm with Dev+C++.
    :
    : [code]
    : int wid=256,heg=256;
    : #define wid 256
    : #define heg 256
    : GLubyte* buffer = new GLubyte[wid*heg];
    : int y=0;
    : GLubyte* p;
    :
    : main(){
    : ....
    : asm(".intel_syntax noprefix

    : //if(y==0) y=heg, pointer=buffer+wid*heg;

    : xor eax,eax

    : or eax,_y

    : jz initYP

    : returnInitYP:

    :

    : mov ecx,_wid

    :

    : mov _pointer,ebx

    : mov _y,eax

    : .att_syntax noprefix");
    : ...
    : }
    : [/code]
    :
    : That was the code calling the code I'm trying to write:
    : [code]
    : asm(".intel_syntax noprefix

    : initYP:

    : //y=heg, pointer=buffer+wid*heg;

    : mov eax,_heg

    : lea ebx,_pointer+256*256

    : jmp returnInitYP

    : .att_syntax noprefix");
    : [/code]
    :
    : As you might see, wid and height in the lea statement are wierd.
    : Since gas cannot do any preprocesing and the manual:
    : http://sourceware.org/binutils/docs-2.17/as/index.html
    : suggests that I'll use the built in featurs of my C compiler.
    :
    : How do I do that?
    :
    : Anyone?
    :
    : EDIT: Firefox crashed when I tried to post this...
    : I posted a workaround instead, but it still doesn't work for constants in the assembly, but almost...
    : Now it looks neater anyway.
    :
    : I still have no clue...
    :

    IMHO statements like a+b*c aren't allowed in ASM, you need to do something like this:
    MOV EAX, b // EAX = b
    MUL c // EAX = EAX * c = b * c
    ADD EAX, a // EAX = EAX + a = b * c + a

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • IDKIDK Posts: 1,784Member
    : : [b][red]This message was edited by IDK at 2006-11-15 14:1:56[/red][/b][hr]
    : : Anyone tried to use gas inlined assembly? I'm trying to do a simple SSE2 mandelbrot program with inline asm with Dev+C++.
    : :
    : : [code]
    : : int wid=256,heg=256;
    : : #define wid 256
    : : #define heg 256
    : : GLubyte* buffer = new GLubyte[wid*heg];
    : : int y=0;
    : : GLubyte* p;
    : :
    : : main(){
    : : ....
    : : asm(".intel_syntax noprefix

    : : //if(y==0) y=heg, pointer=buffer+wid*heg;

    : : xor eax,eax

    : : or eax,_y

    : : jz initYP

    : : returnInitYP:

    : :

    : : mov ecx,_wid

    : :

    : : mov _pointer,ebx

    : : mov _y,eax

    : : .att_syntax noprefix");
    : : ...
    : : }
    : : [/code]
    : :
    : : That was the code calling the code I'm trying to write:
    : : [code]
    : : asm(".intel_syntax noprefix

    : : initYP:

    : : //y=heg, pointer=buffer+wid*heg;

    : : mov eax,_heg

    : : lea ebx,_pointer+256*256

    : : jmp returnInitYP

    : : .att_syntax noprefix");
    : : [/code]
    : :
    : : As you might see, wid and height in the lea statement are wierd.
    : : Since gas cannot do any preprocesing and the manual:
    : : http://sourceware.org/binutils/docs-2.17/as/index.html
    : : suggests that I'll use the built in featurs of my C compiler.
    : :
    : : How do I do that?
    : :
    : : Anyone?
    : :
    : : EDIT: Firefox crashed when I tried to post this...
    : : I posted a workaround instead, but it still doesn't work for constants in the assembly, but almost...
    : : Now it looks neater anyway.
    : :
    : : I still have no clue...
    : :
    :
    : IMHO statements like a+b*c aren't allowed in ASM, you need to do something like this:
    : MOV EAX, b // EAX = b
    : MUL c // EAX = EAX * c = b * c
    : ADD EAX, a // EAX = EAX + a = b * c + a
    :
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :

    No, I'm just multiplying constants, and constants are calculated by the preproccessor...
  • anthrax11anthrax11 Posts: 511Member
    : : : [b][red]This message was edited by IDK at 2006-11-15 14:1:56[/red][/b][hr]
    : : : Anyone tried to use gas inlined assembly? I'm trying to do a simple SSE2 mandelbrot program with inline asm with Dev+C++.
    : : :
    : : : [code]
    : : : int wid=256,heg=256;
    : : : #define wid 256
    : : : #define heg 256
    : : : GLubyte* buffer = new GLubyte[wid*heg];
    : : : int y=0;
    : : : GLubyte* p;
    : : :
    : : : main(){
    : : : ....
    : : : asm(".intel_syntax noprefix

    : : : //if(y==0) y=heg, pointer=buffer+wid*heg;

    : : : xor eax,eax

    : : : or eax,_y

    : : : jz initYP

    : : : returnInitYP:

    : : :

    : : : mov ecx,_wid

    : : :

    : : : mov _pointer,ebx

    : : : mov _y,eax

    : : : .att_syntax noprefix");
    : : : ...
    : : : }
    : : : [/code]
    : : :
    : : : That was the code calling the code I'm trying to write:
    : : : [code]
    : : : asm(".intel_syntax noprefix

    : : : initYP:

    : : : //y=heg, pointer=buffer+wid*heg;

    : : : mov eax,_heg

    : : : lea ebx,_pointer+256*256

    : : : jmp returnInitYP

    : : : .att_syntax noprefix");
    : : : [/code]
    : : :
    : : : As you might see, wid and height in the lea statement are wierd.
    : : : Since gas cannot do any preprocesing and the manual:
    : : : http://sourceware.org/binutils/docs-2.17/as/index.html
    : : : suggests that I'll use the built in featurs of my C compiler.
    : : :
    : : : How do I do that?
    : : :
    : : : Anyone?
    : : :
    : : : EDIT: Firefox crashed when I tried to post this...
    : : : I posted a workaround instead, but it still doesn't work for constants in the assembly, but almost...
    : : : Now it looks neater anyway.
    : : :
    : : : I still have no clue...
    : : :
    : :
    : : IMHO statements like a+b*c aren't allowed in ASM, you need to do something like this:
    : : MOV EAX, b // EAX = b
    : : MUL c // EAX = EAX * c = b * c
    : : ADD EAX, a // EAX = EAX + a = b * c + a
    : :
    : : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    : :
    : :
    :
    : No, I'm just multiplying constants, and constants are calculated by the preproccessor...
    :

    But you did:
    [code]int wid=256,heg=256;[/code]
    Am I missing something?
  • IDKIDK Posts: 1,784Member
    : : No, I'm just multiplying constants, and constants are calculated by the preproccessor...
    : :
    :
    : But you did:
    : [code]int wid=256,heg=256;[/code]
    : Am I missing something?
    :

    This is the workaround:
    int wid=256,heg=256;
    #define wid 256
    #define heg 256

    I don't want to do like that, only defines (or something similar(like equ in fasm) in the assembly), to optimise the code.

    As you see, I don't use wid and heg as constants anywhere in my assembly code. The defines are there to fool the compiler to still think it's constants, and the integer declaration is there to make it work in assembly.
  • netgertnetgert Posts: 331Member
    : : : No, I'm just multiplying constants, and constants are calculated by the preproccessor...
    : : :
    : :
    : : But you did:
    : : [code]int wid=256,heg=256;[/code]
    : : Am I missing something?
    : :
    :
    : This is the workaround:
    : int wid=256,heg=256;
    : #define wid 256
    : #define heg 256
    :
    : I don't want to do like that, only defines (or something similar(like equ in fasm) in the assembly), to optimise the code.
    :
    : As you see, I don't use wid and heg as constants anywhere in my assembly code. The defines are there to fool the compiler to still think it's constants, and the integer declaration is there to make it work in assembly.
    :

    I don't get it. First you say that they are constants, then you say that they are variables that seem like constants. And even in the former case you are still doing an addition with a non-constant

    And also pay attention that with the defines, "wid" and "heg" are replaced everywhere in the source, so
    [code]
    mov ecx,_wid
    or
    calculate_width();
    [/code]
    becomes
    [code]
    mov ecx,_256
    or
    calculate_256th();
    [/code]
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • IDKIDK Posts: 1,784Member
    : : : : No, I'm just multiplying constants, and constants are calculated by the preproccessor...
    : : : :
    : : :
    : : : But you did:
    : : : [code]int wid=256,heg=256;[/code]
    : : : Am I missing something?
    : : :
    : :
    : : This is the workaround:
    : : int wid=256,heg=256;
    : : #define wid 256
    : : #define heg 256
    : :
    : : I don't want to do like that, only defines (or something similar(like equ in fasm) in the assembly), to optimise the code.
    : :
    : : As you see, I don't use wid and heg as constants anywhere in my assembly code. The defines are there to fool the compiler to still think it's constants, and the integer declaration is there to make it work in assembly.
    : :
    :
    : I don't get it. First you say that they are constants, then you say that they are variables that seem like constants. And even in the former case you are still doing an addition with a non-constant
    :

    I want them to be constants, but then I made a work around that are variables that look like constants.

    : And also pay attention that with the defines, "wid" and "heg" are replaced everywhere in the source, so
    : [code]
    : mov ecx,_wid
    : or
    : calculate_width();
    : [/code]
    : becomes
    : [code]
    : mov ecx,_256
    : or
    : calculate_256th();
    : [/code]
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :

    I think the preproccessor just passes the assembly right to the assembler, and no preproccessing is done. (I may be wrong)

    But both of your examples are wrong.

    #define o a
    for(;;) ;

    doesn't become

    far(;;) ;

    The preproccessor only replaces whole words:

    #define for far
    for(;;) ;

    becomes:

    far(;;) ;
Sign In or Register to comment.