Hmm...
Using C i can create a simple messagebox program 1 kb small:
Using ASM i can get the program 1.5 kb small using some example code I found in the MASM package:
Wasn't ASM supposed to be able to create smaller programs than other languages? Or have I missed something? Can someone help me to get the ASM program smaller than 1kb?
Thanks! :)
Using C i can create a simple messagebox program 1 kb small:
#include <windows.h>
#pragma comment(lib, "user32.lib")
#pragma comment(linker, "/release")
#pragma comment(linker, "/entry:main")
#pragma comment(linker, "/filealign:512")
#pragma comment(linker, "/merge:.rdata=.data")
#pragma comment(linker, "/merge:.text=.data")
#pragma comment(linker, "/warn")
int APIENTRY main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Small program", "Small", MB_OK);
return 0;
}
Using ASM i can get the program 1.5 kb small using some example code I found in the MASM package:
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.code
start:
jmp @F
szDlgTitle db "Small program",0
szMsg db "Small program",0
@@:
push MB_OK
push offset szDlgTitle
push offset szMsg
push 0
call MessageBox
push 0
call ExitProcess
end start
Wasn't ASM supposed to be able to create smaller programs than other languages? Or have I missed something? Can someone help me to get the ASM program smaller than 1kb?
Thanks! :)
Its because of...
#pragma comment(linker, "/filealign:512")
#pragma comment(linker, "/merge:.rdata=.data")
#pragma comment(linker, "/merge:.text=.data")
Those are linker options i think. Use them for the asm obj files.
#pragma comment(linker, "/filealign:512")
#pragma comment(linker, "/merge:.rdata=.data")
#pragma comment(linker, "/merge:.text=.data")
Those are linker options i think. Use them for the asm obj files.
this is how it should look:
: -----------------------------------------
: assemble small.asm into an OBJ file
: -----------------------------------------
\MASM32\BIN\ML.EXE /c /coff small.asm
if errorlevel 1 goto errasm
: --------------------------------------------------
: link the main OBJ file with the resource OBJ file
: --------------------------------------------------
\MASM32\BIN\LINK.EXE /SUBSYSTEM:WINDOWS small.obj /MERGE:.data=.rdata /MERGE:.data=.text
: assemble small.asm into an OBJ file
: -----------------------------------------
\MASM32\BIN\ML.EXE /c /coff small.asm
if errorlevel 1 goto errasm
: --------------------------------------------------
: link the main OBJ file with the resource OBJ file
: --------------------------------------------------
\MASM32\BIN\LINK.EXE /SUBSYSTEM:WINDOWS small.obj /MERGE:.data=.rdata /MERGE:.data=.text
Nice!
Thanks!
Thanks!
Why are you linking to kernel32.lib? I belive in MASM32 (if that is what you are using) that would add the library "linkage" into the file even if you dont use it. So that could incur some extra bytes :)
Also I have noticed that you didnt change the alignment of the asm program. try
org 512
and see if it doesnt cut out some unused space. Also try using a Hex Viewer and see if there are alot of 00 in the exe, meaning that the section alignments are too high.
org 512
and see if it doesnt cut out some unused space. Also try using a Hex Viewer and see if there are alot of 00 in the exe, meaning that the section alignments are too high.
firtsly: ExitProcess is api from KERNEL32.DLL so we need to link it too:grin:
secondly: if change align to 512 app our app wont run, i think that masm sets the align to theone which is perfect for our prog....... but i can be wrong:grin:
lastly: http://www.asmcommunity.net/board/index.php?topic=1953&highlight=size
secondly: if change align to 512 app our app wont run, i think that masm sets the align to theone which is perfect for our prog....... but i can be wrong:grin:
lastly: http://www.asmcommunity.net/board/index.php?topic=1953&highlight=size
If you must, use /FILEALIGN:512 . This is good for small apps, but
for larger apps the beneift shrinks (as well as the benefit of using
section merging), and you 'might' get additional overhead.
for larger apps the beneift shrinks (as well as the benefit of using
section merging), and you 'might' get additional overhead.
Sorry, Didnt think about ExitProcess :) Thanks NEMO for pointing that out :)
Jag thanx.... at last some-one appreciate it:grin: :grin: :grin:
strange, i couldn't find /FILEALIGN: on LINK.EXE help and even in MASM611 - Reference's nothing is mention:confused:
strange, i couldn't find /FILEALIGN: on LINK.EXE help and even in MASM611 - Reference's nothing is mention:confused:
Yeah, it's strange that they forgot to mention /FILEALIGN while they
do mention /ALIGN ... /ALIGN is only useful when dealing with VxDs.
do mention /ALIGN ... /ALIGN is only useful when dealing with VxDs.
ahhhh... thx Micor$oft -- you did it again:grin: