flat assembler
Message board for the users of flat assembler.

Index > Windows > How to create a 'hello world' without include files?

Author
Thread Post new topic Reply to topic
saigon



Joined: 29 May 2006
Posts: 62
saigon 29 May 2006, 18:36
Hello!

I am currently studying ASM and I wanted to have a good and fast ASM compiler, so I crossed with FASM. I downloaded the latest version (1.66) and I liked it much. I looked through the examples and they seemed to impress me.

FASM looks very good to me, but now I just have to get used with it.
The MS COFF example which comes with FASM looks simple, but I had to use polink to link the object file with user32.lib. I hate to link object files with libraries, as some linkers throw errors from which I don't understand anything.

However, the hello.asm source doesn't need linking and FASM creates an exe file directly. This was one of the things that I liked very much. The only problem is, I have to use the win32a.inc include file and what I wanted to have is plain source code without include files.

I tried to cut only the needed functions and declarations from the win32a.inc file, but I failed and FASM started to throw errors.

Enough chit-chat, let's go straight to my question. I want to create a simple hello world program (not a console program, but a win32 program which calls the MessageBox api) without any include files. And I don't want to use object files.

Thank you very much. I appreciate any kind of help.
And thanks to Tomasz for this great product.
Post 29 May 2006, 18:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 29 May 2006, 19:30
The package of fasm for Windows contains the PEDEMO example that doesn't use Win32 headers.
Post 29 May 2006, 19:30
View user's profile Send private message Visit poster's website Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 29 May 2006, 19:53
Thanks for pointing me to it Tomasz. I like this product much more Very Happy
I used to use Turbo Assembler (TASM) from Borland, but it's very expensive and doesn't even have it's own IDE. FASM is free and is by far better than TASM. I am really impressed of this compiler.

I hope to program some good and useful programs using FASM.
I'm looking forward to this project.

Thanks!
Post 29 May 2006, 19:53
View user's profile Send private message Reply with quote
blacky



Joined: 06 Apr 2006
Posts: 32
Location: JA
blacky 29 May 2006, 20:29
Quote:
I used to use Turbo Assembler (TASM) from Borland, but it's very expensive and doesn't even have it's own IDE.


Theres always the RadASM IDE that supports the tasm assembler Wink but i would still stick to fasm.. it rox..
Post 29 May 2006, 20:29
View user's profile Send private message MSN Messenger Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 30 May 2006, 05:50
I have some questions concerning the PEDEMO included with FASM.

1: If I specify an import to one of my own made DLLs, does the user have to include my DLL along with the executable package?

2: How do I optimize this import data section to the minimum?
Code:
section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    dd 0
  user_table:
    MessageBox dd RVA _MessageBoxA
    dd 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0     

I want to have a very small footprint on my applications, so that I ensure there is speed and compactness.

3. I also want to ask, do I have to include the empty fixups data section (.reloc) ?

Thank you very much!
Post 30 May 2006, 05:50
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 30 May 2006, 15:35
1. Such DLL will have to be in program directory or SYSTEM32 directory

2. It cannot be smaller

3. No, you don't have to. .reloc section is not needed in .exe files (but DO NOT rip it off when coding a DLL)
Post 30 May 2006, 15:35
View user's profile Send private message Visit poster's website Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 30 May 2006, 15:57
Thanks for the information!
Could someone explain me how RVA works?
I don't fully understand the import data section I posted above.

Also, I want to ask if it's possible to create a static lib using FASM only. Does anyone have examples?

Thanks!
Post 30 May 2006, 15:57
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum 31 May 2006, 03:09
2 Reverend:
Quote:

1. Such DLL will have to be in program directory or SYSTEM32 directory

Or in the current directory, or in the Windows direcory, or in the directories that are listed in the PATH environment variable.

Quote:

2. It cannot be smaller

Try stripping the .DLL extension (XP only)
Try using ordinals (only for a particular DLL version)

For speed optimization try using DLL binding.

2 saigon:
Quote:

I want to ask if it's possible to create a static lib using FASM only

A static lib is just a container for object files. MS link.exe produces such files. If you have a single object file, there's little sense to make a lib for it.

BTW, you'd better take a look at a topic down there about a couple of bugs in PEDEMO example.
Post 31 May 2006, 03:09
View user's profile Send private message Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 31 May 2006, 05:53
OK, thanks for the info. I guess I'll make a MS COFF program in FASM and link it to a static lib. The PE GUI format makes everything a bit harder to understand and when I use MS COFF, I can use a more dedicated set of functions.

Thanks again!
Post 31 May 2006, 05:53
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 31 May 2006, 19:11
Quantum: 1 - yes, I simplified it a bit Smile. Of course you're right.
2 - I didn't mention such methods as they will make executable not work on every version of indows

saigon: Just compile how many MS COFFs you need, and then use lib.exe from masm package (or polib from pelles compilation of tools). Usage: lib.exe *.obj /out:name.lib
Post 31 May 2006, 19:11
View user's profile Send private message Visit poster's website Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum 31 May 2006, 22:51
2 Reverend:
Quote:

I didn't mention such methods as they will make executable not work on every version of indows

But it's very useful when binding your own DLLs. Significant speed and a little size improvements obtained.

"Remove Fatty Deposits from Your Applications Using Our 32-Bit Liposuction Tools" by Matt Pietrek:
http://www.microsoft.com/msj/archive/S572.aspx

A bit out of date but not yet obsolete Wink

2 saigon:
Quote:

The PE GUI format makes everything a bit harder to understand

FASM gives you much more control than any other assembler (well, nasm rules too). You can layout the import in a separate section, inside your data/code section or even spread it all over your PE32 file, if you like. That's a very useful feature in some cases.
Post 31 May 2006, 22:51
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.