flat assembler
Message board for the users of flat assembler.

Index > Windows > Coff files, Visual Studio 2008, and MINGW questions.

Author
Thread Post new topic Reply to topic
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 08 Oct 2010, 17:06
Using FASMW.EXE how would I get it to produce a coff file that visual studio and MINGW (based off of GCC) can use? Once that file is created for VS 2008 do I "project properties->configuration properties->Linker->Input->Additional Dependencies" or something else? For MINGW what would the procedure be?

Thank you.
Post 08 Oct 2010, 17:06
View user's profile Send private message Send e-mail Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Oct 2010, 18:02
Not sure what object file MinGW uses. I always thought it uses ELF, but never checked really.

Quote:
For MINGW what would the procedure be?

Simply add the .o file to command line.
Post 08 Oct 2010, 18:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Oct 2010, 18:06
DarkAlchemist, In the case of VS, using the "Add > Existing Item..." also works and perhaps that's better since you'll also see the file listed in the project explorer.
Post 08 Oct 2010, 18:06
View user's profile Send private message Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 08 Oct 2010, 19:08
Which item do I add as I have yet to see a .coff produced via the FASMW.exe program or do I need another ide?

Funny thing is that I do not even see a way to produce a .o via FASMW.exe. Maybe I am too used to toggles in the ide these days and there is possibly a flag I need to set in the source?
Post 08 Oct 2010, 19:08
View user's profile Send private message Send e-mail Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Oct 2010, 20:04
Here you have a thread related to this: http://board.flatassembler.net/topic.php?t=11984

It is OK to use .OBJ, at least when I've tried (see the thread), it worked and it is a MS COFF. To make FASM create ".o" it is "format ELF" what you have to use. However, if you are trying to force extensions that not match what fasm uses for the target format, then you could use, for instance, "format ms coff as 'coff'" or "format ms coff as 'o'" or "format foo as 'bar'", etc.
Post 08 Oct 2010, 20:04
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 08 Oct 2010, 20:12
vid wrote:
Not sure what object file MinGW uses. I always thought it uses ELF, but never checked really.
No, it doesn't, MinGW's object files are MS COFFs.
Post 08 Oct 2010, 20:12
View user's profile Send private message Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 08 Oct 2010, 22:54
LocoDelAssembly wrote:
Here you have a thread related to this: http://board.flatassembler.net/topic.php?t=11984

It is OK to use .OBJ, at least when I've tried (see the thread), it worked and it is a MS COFF. To make FASM create ".o" it is "format ELF" what you have to use. However, if you are trying to force extensions that not match what fasm uses for the target format, then you could use, for instance, "format ms coff as 'coff'" or "format ms coff as 'o'" or "format foo as 'bar'", etc.
Yep, I saw this last night but when I tried I was getting some errors.
Code:
include 'win32ax.inc'

_hello db 'Hello World',0
_title db 'FASM rocks HARD',0
start:
        invoke MessageBox, NULL, _hello, _title, MB_OK
        invoke ExitProcess,0
.end start     
When I try to do the things in that thread I just get more and more errors.

Is there some documentation I can read about what to do when I wish to write a procedure? Something I can understand what it is I need to do and what I am currently doing wrong?
Post 08 Oct 2010, 22:54
View user's profile Send private message Send e-mail Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Oct 2010, 11:48
Have you seen my old examples of mixing C and Asm? It worked with Visual C++ (compiler that Visual Studio suite uses), but I never tried to do it directly from IDE. I prefer command line. It has examples of how to write proper procedures which can be called from C/C++ code.
Post 09 Oct 2010, 11:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 09 Oct 2010, 20:45
No, I haven't but I think it would work, it should actually, if I understood FASM better in this regard. I can't even get the simple code I wrote to convert into a procedure then get FASM to output the coff file.
Post 09 Oct 2010, 20:45
View user's profile Send private message Send e-mail Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 11 Oct 2010, 20:17
Take a look here:

http://sites.google.com/site/rugxulo/paq8o8z-Jan13-lite.tgz?attredirects=0

You can use FASM + MinGW (or DJGPP, even). I'm a pretty crappy programmer, but despite that, it seems to work!

Trivia: MinGW and Cygwin both output MS COFF for Windows, which is (sadly) incompatible with DJGPP's COFF (relocations?). However, it seems recent versions of GNU ld handle both okay. And I know MinGW and Cygwin ld are each built with ELF support too. But only rare things like Bellard's TinyC (TCC) use ELF there (yes, even on Windows, for object files, but not final .EXEs obviously). Okay, well, DJELF exists too, but nobody [but me] cares, that's DOS.
Post 11 Oct 2010, 20:17
View user's profile Send private message Visit poster's website Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 11 Oct 2010, 23:25
I downloaded that file and will look it over later, thank you.

edit: This is just some program so what exactly am I supposed to be looking for?

Btw, my IDE for MSVC is Visual Studio and WxDevCPP for Mingw.
Post 11 Oct 2010, 23:25
View user's profile Send private message Send e-mail Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 12 Oct 2010, 06:29
DarkAlchemist wrote:

edit: This is just some program so what exactly am I supposed to be looking for?


Of course it's just "some" program, it's an example of using FASM and G++. See paq8o8z/src/otherasm/fast-paq.fsm . I've used that [sic] to build under Linux, Win32 (MinGW), and DOS (DJGPP).
Post 12 Oct 2010, 06:29
View user's profile Send private message Visit poster's website Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 12 Oct 2010, 11:17
Well, this is where the problem lies, for me and my lack of understanding:
Code:
format ms coff
include 'win32ax.inc'

_hello db 'Hello World',0
_title db 'FASM rocks HARD',0
start:
        invoke MessageBox, NULL, _hello, _title, MB_OK
        invoke ExitProcess,0
.end start    
refuses to assemble but remove the format ms coff and it assembles, and runs, fine.

So, what am I doing wrong in the above example?
Post 12 Oct 2010, 11:17
View user's profile Send private message Send e-mail Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Oct 2010, 15:06
Okay, here's the example how to link with MinGW:

fasmy_proc.asm:
Code:
format ms coff

;include header usable for COFF
include 'win32a.inc'

;declare external proc we use here
extrn "_MessageBoxA@16" as MessageBox:dword    ;number behind @ is number of arguments times 4

;"publish" procedure this object provides to other objects
public fasmy_proc as "_fasmy_proc@0"

section '.data' data readable writeable
;in fact, this should go to "const" read-only section, but nevermind

_hello db 'Hello World',0 
_title db 'FASM rocks HARD',0 

section '.text' code readable executable

;very simple procedure, which doesn't take any arguments
;declare as: void fasmy_proc();
fasmy_proc:

        ;just display MessageBox
        ;Note: use "stdcall" for WinAPI procs, not "invoke"
        ;invoke is only for imports constructed by FASM macros.
        stdcall MessageBox, NULL, _hello, _title, MB_OK

        ;return to caller
        retn    


test.c:
Code:
void __stdcall fasmy_proc();

int main()
{
    fasmy_proc();
    return 0;
}    


command line:
Code:
fasm fasmy_proc.asm fasmy_proc.o
gcc test.c fasmy_proc.o
    


Things get bit more complicated once you want to pass arguments and return values.
Post 12 Oct 2010, 15:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist 12 Oct 2010, 15:26
Well, see, the above I mostly understand but so much I do not. I have never linked C/C++ and ASM before and this is why I wanted some really good documentation on what you just did plus this was a simple function but in the real world arguments and return values are needed.
Post 12 Oct 2010, 15:26
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Oct 2010, 17:03
DarkAlchemist,

Linker (while I prefer RSTS/E term, «task builder») does quite staightforward job, it starts from object containing entry point (your 2010-10-12 14:17 example won't compile because of entry directive in .end macroinstruction expansion, by the way), adds objects containing names referenced by it (not with PE import directory, but with extrn directive), adds objects containing names referenced by them, adds objects containing names referenced by them, ad infinitum. Wink
Post 12 Oct 2010, 17:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Oct 2010, 17:41
DarkAlchemist: okay, then google what you can about "stdcall" and "ccall", and how to write such procs. It's not that hard.
Post 12 Oct 2010, 17:41
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 14 Oct 2010, 02:41
rugxulo wrote:
Trivia: MinGW and Cygwin both output MS COFF for Windows, which is (sadly) incompatible with DJGPP's COFF (relocations?).
Yep, relocations. Iirc the difference is that one format stores "0" for relocatable addresses and lets the linker do full calculation from symbol tables, the other stores a un-relocated base address where the linker can basically add a relocation offset.

Also iirc mscoff and djgpp-coff use the same magic identifier, so you can't discern between the two? At least I recall running my head against walls many years ago when I tried building bintools for djgpp with both dj- and ms-coff support. I finally did the sane thing and ditched djgpp... if you need C development under DOS, you're probably better off using win32 console apps and a dos extender that can handle those.

_________________
Image - carpe noctem
Post 14 Oct 2010, 02:41
View user's profile Send private message Visit poster's website 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.