flat assembler
Message board for the users of flat assembler.

Index > Main > size statistics in .com and .exe files

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 09 Jan 2010, 22:52
When I compile a .com file, fasmw shows me the size (in bytes) of each change i do.

For example:
Code:
org 100h
mov dx, msg
mov ah, 9h
int 21h
mov ah, 4Ch
int 21h
msg db 'hello word$'
     ; compile msg -> 2 passes, 22 bytes    
If i add any line:
Code:
org 100h
mov dx, msg
mov ah, 9h
int 21h
mov ah, 4Ch
int 21h
xor ax,ax         ; <- odd
msg db 'hello word$' 
     ; compile msg -> 2 passes, 24 bytes    


But the same does not happen with .exe files. I can coding, and coding, and coding, and it does not shows me each change. It just shows me the changes in big steps (like ~100bytes). (sorry i'm don't finding the words to describe correctly)

Why?

_________________
Sorry if bad english.
Post 09 Jan 2010, 22:52
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Jan 2010, 00:19
because .exe files are aligned to "pages". I suspect it's 128 bytes from your ~100 case. Are you talking about PE (Windows) exe files or DOS exe files btw?

PE will have at least 512 bytes alignment. If you want to see the exact size of your code use "format binary"
Post 10 Jan 2010, 00:19
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 10 Jan 2010, 00:22
Win exe.

'format binary' generates a .bin ?
Post 10 Jan 2010, 00:22
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 10 Jan 2010, 00:23
yep, also

format binary as 'any'
Post 10 Jan 2010, 00:23
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Jan 2010, 00:50
Win exe has PE (portable executable) format, and the file is aligned to at least 512 bytes (by default, some HLL compilers go as high as 16K Shocked).

and yes you can put "format binary as 'xyz'" where 'xyz' is whatever extension you want!
Post 10 Jan 2010, 00:50
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 10 Jan 2010, 09:40
nice Smile
Post 10 Jan 2010, 09:40
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 10 Jan 2010, 21:54
MZ EXEs use (hardcoded!) 512-byte page size Smile

PE EXEs can have lower file alignment than 512 bytes, but that isn't supported for usermode executables on all Windows versions (iirc it works fine for drivers, though).
Post 10 Jan 2010, 21:54
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Jan 2010, 22:40
Interesting, I didn't know that. Thanks. Smile
Post 10 Jan 2010, 22:40
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 10 Jan 2010, 22:45
Borsuc wrote:
Interesting, I didn't know that. Thanks. Smile
I haven't seen it documented anywhere, either - at least not in any official MS docs. There's a lot of things about PE executables that isn't super obvious, nor is documented... and it's not just 9x vs. NT, there's differences between NT versions as well.

_________________
Image - carpe noctem
Post 10 Jan 2010, 22:45
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 12 Jan 2010, 08:18
Teehee wrote:
When I compile a .com file, fasmw shows me the size (in bytes) of each change i do.


Really ???

Quote:
But the same does not happen with .exe files. I can coding, and coding, and coding, and it does not shows me each change. It just shows me the changes in big steps (like ~100bytes).


DOS COM: no align (AKA 1 Byte)

DOS MZ EXE: 16-Bytes align in the header but no align in file size (maybe some bloat linkers align to 512 Bytes Laughing )

Win32 PE EXE (app or driver or "special"): 512-Bytes align (down to 16 Bytes might work on NT but not on ME, some bloat linkers align to 4 KiB instead (or even 16 KiB ???) Laughing )

NOTHING: like ~100bytes
Post 12 Jan 2010, 08:18
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 12 Jan 2010, 09:30
DOS386 wrote:
DOS MZ EXE: 16-Bytes align in the header but no align in file size (maybe some bloat linkers align to 512 Bytes Laughing )
Yeah, since EXE size is specified as number-of-512byte-pages + remainder, size doesn't have to be aligned. Wouldn't really have much practical consequences if only full pages could be specified, though... can you show me a device with sector-size smaller than 512 bytes? Smile

DOS386 wrote:
Win32 PE EXE (app or driver or "special"): 512-Bytes align (down to 16 Bytes might work on NT but not on ME,
Why "Me" and not "9x"?

DOS386 wrote:
some bloat linkers align to 4 KiB instead (or even 16 KiB ???) Laughing )
Aligning sections to hardware pagesize kinda makes sense, imho - and for any realistically sized project the amount of wasted bytes will be inconsequential.

16KB alignment, though? Where have you seen that? O_o

_________________
Image - carpe noctem
Post 12 Jan 2010, 09:30
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 12 Jan 2010, 09:33
f0dder wrote:
Why "Me" and not "9x"?


ME is more famous Shocked

Quote:
16KB alignment, though? Where have you seen that? O_o


See above: post by Borsuc
Post 12 Jan 2010, 09:33
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 12 Jan 2010, 09:52
DOS386 wrote:
f0dder wrote:
Why "Me" and not "9x"?

ME is more famous Shocked
Wouldn't that be infamous? Wink - it still belongs in the 9x class, anyway.

DOS386 wrote:
Quote:
16KB alignment, though? Where have you seen that? O_o

See above: post by Borsuc
[/quote]Ah yes, it was Borsuc who posted this. I'd like to know which products do alignment like this, never seen a default higher than 4kb, and it seems a bit silly... only use I can think of would be debug-mode executable for "edit & continue", but there you would rather insert padding between functions, rather than having big section align.

_________________
Image - carpe noctem
Post 12 Jan 2010, 09:52
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 12 Jan 2010, 17:54
I don't know -- I've just seen some poor apps with 16K alignment. I don't know if they use default settings or not, it was an assumption given the fact that it was noobs who made them and since they don't care about it why would they increase the default? But, just an assumption on my part.
Post 12 Jan 2010, 17:54
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.