flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > interface C-ASM

Author
Thread Post new topic Reply to topic
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95 03 May 2013, 01:40
I started studying C recently, using gcc as compiler, but I found out that it uses AT&T syntax for inline ASM, which is simply horrible!

So I would like to write my ASM functions in a file and then call them from another C file, anyone knows how to do that?
I think I read something about this in the forum but I cannot find it anymore...

Thank in advance!
Post 03 May 2013, 01:40
View user's profile Send private message Reply with quote
Bob++



Joined: 12 Feb 2013
Posts: 92
Bob++ 03 May 2013, 01:54
Currently gcc supports intel's assembly syntax. Not only output it,inline too.
Put this
Code:
.intel_syntax noprefix    
before intel's assembly,and use
Code:
-masm=intel    
.
But don't forget to switch back to ATT's assembly after:
Code:
.att_syntax noprefix    


EDIT:

To use non-inline assembly routines with gcc,it's very simple. Make you assembly generate objcode(on FASM,see "format" section from fasm's documentation) code and then compile with gcc to an executable as following:
Code:
gcc foo.o etc.c -o exe    
Post 03 May 2013, 01:54
View user's profile Send private message Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95 03 May 2013, 02:14
Thanks a lot for the fast answer, I prefer to use non-inline assembly so I have some other questions:

Should the assembly routines have some particular name? (begin with underscore or something)

How do I pass parameters?

And if there is a return value where should it be?

The compiler deals with the values of registers or my routines should worry about restoring them?

If you could make me a very basic example, a function that adds two values and return the sum or something like that, I would find it truly useful since I know really a little of C!
Thank again!
Post 03 May 2013, 02:14
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 841
Location: Jakarta, Indonesia
TmX 03 May 2013, 02:26
Maybe you'd like to try this:
http://www.flatassembler.net/examples/msvc.zip

Very Happy
Post 03 May 2013, 02:26
View user's profile Send private message Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95 03 May 2013, 02:30
That does look exactly what I was searching for, thanks a lot!

I'll look at this files, I'll post here again in case I still have some doubts Smile
Post 03 May 2013, 02:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.