The MASM Forum

General => The Workshop => Topic started by: Gunther on February 08, 2013, 11:26:09 AM

Title: Simple Win32 example with as and ld
Post by: Gunther on February 08, 2013, 11:26:09 AM
The archive mesbox.zip contains both, a C program and an assembly language program; the functionality is the same (displaying a messagebox and terminating). Both are generated with MinGW 4.6.2. The C source is compiled with: gcc -o hello.exe hello.c -mwindows. The result is a 50 KB EXE.

The assembly language source is in mesbox.s (Intel syntax); for building the program, please check out build_mesbox.bat. There's another, more sophisticated example by Vortex, which you can check here: http://masm32.com/board/index.php?topic=1140.msg10851#msg10851 (http://masm32.com/board/index.php?topic=1140.msg10851#msg10851). Thank you, Erol.  :t

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: qWord on February 08, 2013, 11:49:34 AM
Just for your information, LD breaks with Microsoft's PE/COFF specification by default: If you look into hello.exe you will find section names greater than 8, which is not allowed for PEs.
If one is interest in conform executables, he might use the well documented switch "-disable-long-section-names".
Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 08, 2013, 01:18:34 PM
Hi qWord,

Quote from: qWord on February 08, 2013, 11:49:34 AM
Just for your information, LD breaks with Microsoft's PE/COFF specification by default: If you look into hello.exe you will find section names greater than 8, which is not allowed for PEs.
If one is interest in conform executables, he might use the well documented switch "-disable-long-section-names".

you're probably right, but I'm the false adressee. You should leave a comment for the compiler builders.

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: Magnum on February 08, 2013, 01:39:14 PM
It's interesting how much bigger the C version is.  23X

Is MinGW an optimizing compiler ?

Andy
Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 08, 2013, 01:54:28 PM
Hi Andy,

Quote from: Magnum on February 08, 2013, 01:39:14 PM
It's interesting how much bigger the C version is.  23X

Is MinGW an optimizing compiler ?

Andy

I don't know, but MinGW is the port from the the Linux gcc for the Windows OS. It's a fairly good compiler. You should give it a try, if your system is repaired.

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 08, 2013, 02:32:06 PM
Hi qWord,

Quote from: qWord on February 08, 2013, 11:49:34 AM
If one is interest in conform executables, he might use the well documented switch "-disable-long-section-names".

Fixed.

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: Greenhorn on February 09, 2013, 12:41:40 AM
BTW, the reason why the C version is so huge is explained here (http://mingw.org/wiki/Large_executables).
Title: Re: Simple Win32 example with as and ld
Post by: anta40 on February 09, 2013, 03:03:29 AM
Quote from: Greenhorn on February 09, 2013, 12:41:40 AM
BTW, the reason why the C version is so huge is explained here (http://mingw.org/wiki/Large_executables).

That page is about C++, and because C++ has more language features than C, it's not surprising that C++ executables can be larger than their C counterparts. A canonical hello world C++ program, compiled with older versions of MinGW g++, could yield a ± 500 KB exe.
Title: Re: Simple Win32 example with as and ld
Post by: Magnum on February 09, 2013, 03:09:38 AM
Greenhorn,

That is interesting info.

Even if it has the debug info, size isn't that bad.

I have seen some Visual Basic programs that were about 100x the size of an assembly program that does the same thing.

Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 09, 2013, 04:40:44 AM
Hi Andy,

Quote from: Magnum on February 09, 2013, 03:09:38 AM
I have seen some Visual Basic programs that were about 100x the size of an assembly program that does the same thing.

that is clear, because a HLL compiler produces a lot of red band, which isn't really necessary for executing.

At the moment, I'm experimenting with as and ld under Win7 (64 bit). It's a mess, because the linker can't find the necessary libraries. There is on the other hand such a tool like Bogdan's SoAsm; it's well written, lean and under active development. But I can't re-compile the provided Linux object code, because it's for 32 bit. Bad luck. May be that Bogdan can provide a native 64 bit object file. I've asked him via PM. SolAsm seems to be a great tool and is useable under Windows and Linux.

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: jcfuller on February 09, 2013, 04:58:16 AM
Using this gcc(4.7.2) distro: http://nuwen.net/mingw.html
the exe is 8,704

Of course using Tiny c the size is the same as "as" -> 2048

James
Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 09, 2013, 05:43:12 AM
Hi James,

Quote from: jcfuller on February 09, 2013, 04:58:16 AM
Using this gcc(4.7.2) distro: http://nuwen.net/mingw.html
the exe is 8,704

is that the 64 bit Windows version?

Gunther
Title: Re: Simple Win32 example with as and ld
Post by: jcfuller on February 09, 2013, 06:08:07 AM
No. 32bit only.

I primarily use the TDM version http://tdm-gcc.tdragon.net/

It is 32/64

James

Title: Re: Simple Win32 example with as and ld
Post by: Vortex on February 09, 2013, 06:10:17 AM
Hi Gunther,

Thanks for your example :t
Title: Re: Simple Win32 example with as and ld
Post by: Vortex on February 09, 2013, 06:20:08 AM
Quote from: qWord on February 08, 2013, 11:49:34 AM
If you look into hello.exe you will find section names greater than 8

I am afraid this not true. Analyzing the executable with LordPE :

Section name     Length of section name

.text     5
.data     5
.rdata     6
.eh_fram     8
.bss     4
.idata     6
.CRT     4
.tls     4
.debug_a     8
.debug_p     8
.debug_p     8
.debug_i     8
.debug_a     8
.debug_l     8
.debug_f     8
.debug_s     8
.debug_l     8
.debug_r     8


Thanks for explaining the -disable-long-section-names option. :t
Title: Re: Simple Win32 example with as and ld
Post by: qWord on February 09, 2013, 06:23:12 AM
Quote from: Vortex on February 09, 2013, 06:20:08 AMI am afraid this not true.
it is true  ;)
Quote from: Gunther on February 08, 2013, 02:32:06 PM
Hi qWord,

Quote from: qWord on February 08, 2013, 11:49:34 AM
If one is interest in conform executables, he might use the well documented switch "-disable-long-section-names".

Fixed.

Gunther

Title: Re: Simple Win32 example with as and ld
Post by: Vortex on February 09, 2013, 06:35:53 AM
Hi qWord,

Probably, I didn't make clear my statement : Size of sections names <= 8  in Gunther's example hello.exe
Title: Re: Simple Win32 example with as and ld
Post by: qWord on February 09, 2013, 06:41:23 AM
yes, he has rebuild the example.
Read wjr's post for an other eaxmple: http://masm32.com/board/index.php?topic=1091.msg10331#msg10331
Title: Re: Simple Win32 example with as and ld
Post by: Vortex on February 09, 2013, 06:46:32 AM
Sorry, reading very fast all the postings. Yes, he rebuilt the example. OK.
Title: Re: Simple Win32 example with as and ld
Post by: Gunther on February 09, 2013, 10:25:33 AM
Hi Erol,

Quote from: Vortex on February 09, 2013, 06:10:17 AM
Hi Gunther,

Thanks for your example :t

it isn't a big deal. But my 64 bit experiments are not so successful, so far.

Gunther