flat assembler
Message board for the users of flat assembler.

Index > Windows > Compiler bug?

Author
Thread Post new topic Reply to topic
snifit



Joined: 10 Dec 2004
Posts: 12
Location: Sweden
snifit
I'm using flat assembler 1.56 for Win32 GUI (the 14 December build) and found something interesting when compiling the "same" code (2 lines switched place).

Example one
Code:
format PE console
entry start

BUFSIZE         = 1024

section '.data' data readable writeable
  letter db 0
  buffer rb BUFSIZE

section '.code' code readable executable
  start:
        xor     eax,eax
        ret
    

When compiling this example it ALLWAYS takes 1536 bytes (the size of BUFSIZE does not matter)
BUFSIZE = 1024 => 1536 bytes executable
BUFSIZE = 10240 => 1536 bytes executable

Example two - bug?
Code:
format PE console
entry start

BUFSIZE         = 1024

section '.data' data readable writeable
  buffer rb BUFSIZE
  letter db 0

section '.code' code readable executable
  start:
        xor     eax,eax
        ret
    

As you can see the only difference now is that the "buffer" and "letter" line has switched place, and now the executable changes if you change the BUFSIZE!
BUFSIZE = 1024 => 2560 bytes executable
BUFSIZE = 10240 => 11776 bytes executable

I guess this is a bug, unless I've missed some important part Smile
And btw, if "letter db 0" is changed to "letter db ?" then both examples gets the same executable size (1024 bytes).
Post 02 Jan 2005, 21:31
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
No, it is not a bug. It is normal behaviour. The uninitialized data (i.e. declared with rb, rw, rd, rq or "db ?", etc. and when it is declared at the end of the data section (after all initialized data) will not be included in the executable file, but will be created directly in memory during loading of PE executable (remember this data memory is only reserved, it doesn't contains defined data).
So, in order to get minimal file size, you MUST place your uninitialized data at the end of the sections.

Regards.
Post 02 Jan 2005, 23:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
snifit



Joined: 10 Dec 2004
Posts: 12
Location: Sweden
snifit
Ah that explains it, thanks.
Post 02 Jan 2005, 23:10
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
As you can see you have written code AFTER data, but you still have minimal size exe. In PE file code is right after the header and data is always at the back end, nice optimization Wink concerning size.
Post 04 Jan 2005, 22:12
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
often uninitialized data placed in special section

Code:
section '.idata' data readable
   szTest db "test",0

section '.udata' readable writeable 
   szBuffer rb 1024
    
Post 05 Jan 2005, 08:48
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.