News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Simple Win32 example with as and ld

Started by Gunther, February 08, 2013, 11:26:09 AM

Previous topic - Next topic

Gunther

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. Thank you, Erol.  :t

Gunther
You have to know the facts before you can distort them.

qWord

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".
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

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
You have to know the facts before you can distort them.

Magnum

It's interesting how much bigger the C version is.  23X

Is MinGW an optimizing compiler ?

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Gunther

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
You have to know the facts before you can distort them.

Gunther

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
You have to know the facts before you can distort them.

Greenhorn

BTW, the reason why the C version is so huge is explained here.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

anta40

Quote from: Greenhorn on February 09, 2013, 12:41:40 AM
BTW, the reason why the C version is so huge is explained here.

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.

Magnum

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.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Gunther

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
You have to know the facts before you can distort them.

jcfuller

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

Gunther

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
You have to know the facts before you can distort them.

jcfuller

No. 32bit only.

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

It is 32/64

James


Vortex


Vortex

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