flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > MS COFF and help converting NASM to fasm

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
MS COFF and help converting NASM to fasm
Hi.

How can I use the command line tool, (FASM.EXE), to build MS COFF files instead of executables, by using the format MS COFF directive with high level istructions, like invoke ?
The following example does not work:

format MS COFF

include 'C:\Fasm\INCLUDE\win32ax.inc'


.code


start:
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",0,MB_OK
invoke ExitProcess,0

.end start


Manos.
Post 20 Nov 2016, 11:41
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
There is an MSCOFF.ASM example file in the download:

Code:

; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
        push    0
        push    _caption
        push    _message
        push    0
        call    [MessageBox]
        ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0

Post 20 Nov 2016, 12:26
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
I know the above example.

But instead of: extrn '__imp__MessageBoxA@16' as MessageBox:dword
I want to use: include 'C:\Fasm\INCLUDE\win32ax.inc'
and instead of pushing the parameters on the stack and calling the function,
I want to use: invoke MessageBox, etc,
just like MASM projects.

Manos.
Post 20 Nov 2016, 12:53
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
You don't need to include the entire win32 set. Just this might be all you need:

Code:
include 'macro/proc32.inc'

Post 20 Nov 2016, 13:00
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece

revolution wrote:
You don't need to include the entire win32 set. Just this might be all you need:

Code:
include 'macro/proc32.inc'



It is not enough.

Try to assemble the following code:

format MS COFF

include 'C:\Fasm\INCLUDE\win32ax.inc'


.code


start:
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",0,MB_OK
invoke ExitProcess,0

.end start


Manos.
Post 20 Nov 2016, 13:33
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
You don't need ".end" with COFF. The linker will set the entry address. And don't use win32ax, try the include I posted above.

Code:
format MS COFF

include 'macro/proc32.inc'

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

public MyCode

MyCode:
        invoke MessageBox,0,caption,message,0
        ret

section '.data' data readable writeable

caption db 'Win32 assembly',0
message db 'Coffee time!',0

Post 20 Nov 2016, 13:38
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
Hi revolution.

I know your above example.

But because I am building an IDE for plain C, MASM and FASM,
I would like to avoid the: extrn '__imp__MessageBoxA@16' as MessageBox:dword.

I want to use: 'C:\Fasm\INCLUDE\win32ax.inc',
like I do in MASM.

Manos.
Post 20 Nov 2016, 13:58
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
win32ax won't work for you. You will need to write some type of macro or include file to create all the import names. You will need the extrn's to be included somewhere in the source that fasm sees. Currently there is no file that will do that for you in the fasm download.
Post 20 Nov 2016, 14:10
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
Yes, you are right.

I have to implement my own include files.

Thank you for your replies,

Manos.
Post 20 Nov 2016, 15:44
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
In NASM there is the expression: times ($$-$) & 3 nop

How can I phrase the above in FASM ?

Thanks,
Manos.
Post 21 Nov 2016, 21:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
Replace & with and
Post 22 Nov 2016, 03:08
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece

revolution wrote:
Replace & with



Thang you, it is correct, but I have also to replace the: $$-$ with: $-$$
The correct is: times ($-$$) and 3 nop

Manos.
Post 22 Nov 2016, 11:53
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699

Manos wrote:
The correct is: times ($-$$) and 3 nop

Okay, I'm not 100% with NASM syntax. In that case you could also write:

Code:
align 4



Last edited by revolution on 22 Nov 2016, 13:38; edited 1 time in total
Post 22 Nov 2016, 13:05
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece

revolution wrote:

Manos wrote:
The correct is: times ($-$$) and 3 nop

Okay, I'm not 100% with NASM syntax. In that case you could also write:

Code:
align 4




I thought to use: align 4, but I prefer to avoid macros, because my C compiler can emit plain FASM code.
My C compiler, (wcc32), accepts also inline assembly.
Because my IDE use wcc32, I wish my IDE to mix C and assembly modules.
I have implemented, also a linker, named wlink32 and
a RC compiler, but I have upload only wlink32 for now.
Have a look there: http://www.manoscoder.gr/w32cc/viewtopic.php?f=12&t=24

Thank you,
Manos.
Post 22 Nov 2016, 13:37
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
Align is not a macro in fasm.
Post 22 Nov 2016, 13:38
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece
OK.

I 'll test this later.

Manos.
Post 22 Nov 2016, 13:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
Oh wait. $-$$ gives you the offset. I think that $$-$ is what you wanted, the negative offset.
Post 22 Nov 2016, 13:40
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece

revolution wrote:
Oh wait. $-$$ gives you the offset. I think that $$-$ is what you wanted, the negative offset.



The first worked fine.

I 'll test for the $$-$

Manos.
Post 22 Nov 2016, 13:50
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699

Manos wrote:

revolution wrote:
Oh wait. $-$$ gives you the offset. I think that $$-$ is what you wanted, the negative offset.



The first worked fine.

If the positive offset is 1 mod 4 then you get only one byte of padding. If the positive offset is 3 mod 4 then you get three bytes of padding.
Post 22 Nov 2016, 14:05
View user's profile Send private message Visit poster's website Reply with quote
Manos



Joined: 24 Aug 2003
Posts: 35
Location: Greece

revolution wrote:

Manos wrote:

revolution wrote:
Oh wait. $-$$ gives you the offset. I think that $$-$ is what you wanted, the negative offset.



The first worked fine.

If the positive offset is 1 mod 4 then you get only one byte of padding. If the positive offset is 3 mod 4 then you get three bytes of padding.



Yes, you are right.
I tested the: $$-$ and it works OK also.
Finally, I 'll use the: $$-$

Thank you again.

P.S.
Did you download my wlink32 ?

Manos.
Post 22 Nov 2016, 14:13
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:  
Goto page 1, 2  Next

< 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.