I have a super simple .ASM file:

.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

invoke ExitProcess, NULL
end main

Now when i compile and link it, i get the following (shown with dumppe -disasm):

00401000 start:
00401000 6A00 push 0
00401002 E801000000 call fn_00401008
00401007 CC int 3
00401008 fn_00401008:
00401008 FF2500204000 jmp dword ptr

My questions are:

1. Why at 00401007 is there CC INT 3 Interrupt 3 trap to debugger ?

2. Why is there a call to 00401008 fn_00401008 just to do a JuMP to the ExitProcess routine ?

I guess I am wondering why the code is not like this:

00401000 start:
00401000 6A00 push 0
00401008 FF2500204000 jmp dword ptr

My only guess is that I compiled/linked with debug and the extra call to jmp is there so that the debugger can trap the call, before the jump.

So how do I turn off DEBUG in ML/LINK ?
Posted on 2002-07-17 19:39:19 by James_Ladd
the int 3 is there to stop the code from getting to the end(no ret)
and the jumps are for OS compatablility, it jumps insteds of a direct call.
Posted on 2002-07-17 20:08:30 by Qages
1) 0CCh is there to trap errors - rather weird the masm emites this. Yet a sign that is is
a highlevel assemvler.

2) to do with your typedefs and such (yeah, masm is highlevel). You "CALL" "directly" the API,
which means you go through linker proxies... with some other typedefs and such you can go
Posted on 2002-07-17 21:20:19 by f0dder
Ok, I changed the code to what the disassembly showed:

push 0
mov eax, ExitProcess
jmp eax

and the assembler still created the following:

00401000 6A00 push 0
00401002 B80A104000 mov eax,40100Ah
00401007 FFE0 jmp eax
00401009 CC int 3
0040100A FF2500204000 jmp dword ptr

I find this strange, but if thats what its got to do, then thats what its got to do.
If you know why can you let me in on it ?
ie: why the code generated does a JMP to 0040100A just to do another jump ?

Is there a "DONT COMPILE FOR DEBUG" option in ml and/or link ?

Posted on 2002-07-18 01:27:16 by James_Ladd
Gotta love FASM even more now:

00401000 start:
00401000 6A00 push 0
00401002 FF1535204000 call dword ptr [ExitProcess]


Format PE GUI 4.0

include 'stdcall.inc'
include 'import.inc'

stdcall [ExitProcess], 0

section '.idata' import data readable writeable

library kernel, 'KERNEL32.DLL'
import ExitProcess, 'ExitProcess'

18.07.2002 09:00 1.536 test_fasm.exe
18.07.2002 08:42 2.560 test_masm.exe
Posted on 2002-07-18 01:50:30 by bazik
the 0CCh is there because .code segment is dword aligned and masm uses 0CCh as fill byte. It would vanish if you code a "nop" after ExitProcess.
Posted on 2002-07-18 03:01:06 by japheth
Is there a way to avoid that CALL / JMP to the API?
(didn't bitRAKE post a macro for that?)

Just interested about that.....
/me is future FASM user :grin:
Posted on 2002-07-18 03:19:15 by bazik

MASM32 tool l2extia.exe exists just for that purpose.
Posted on 2002-07-18 05:15:12 by japheth


MASM32 tool l2extia.exe exists just for that purpose.

Thanks, never looked in that folder :)
Posted on 2002-07-18 05:30:14 by bazik

I go blind and mad making useful toys and you don't even look in the folder ?:grin:


Posted on 2002-07-18 05:39:28 by hutch--
Ain't it good to know that MASM always did it right.


00401000 start:
00401000 6A00 push 0
00401002 FF1500204000 call dword ptr [ExitProcess]

Just used the headers generated by L2EXTIA.EXE


hutch@movsd.com :tongue:
Posted on 2002-07-18 05:44:00 by hutch--


I never looked in the folders with a '*' and deleted the folders with a '#' :)
Maybe MASM32v8 should include the EXAMPLE and ICZTUTES folder in a seperate package?
Posted on 2002-07-18 05:53:19 by bazik

Do you want to answer the flood of email about why the examples don't work or where are they or how do you write THIS code ?

After being mail bombed for a few versions, splitting it up so that the installation was not automatic and complete would be a formula for a bandwidth crisis that I don't need. :tongue:


Posted on 2002-07-18 06:04:23 by hutch--
Good point, Steve ! ;)

What about moving them in a folder "EXAMPLES" ?
I'd only need to delete one then :tongue:
Posted on 2002-07-18 06:14:24 by bazik
Ok, can someone tell me what this tool does and how to run it ?

Posted on 2002-07-18 18:05:33 by James_Ladd
Same as l2inca.exe, but generates direct imports without a jump table.
Posted on 2002-07-18 18:30:48 by comrade

It is a utility that reads the linker data from the standard Microsoft libraries and writes a set of INCLUDE files that are in EXTERNDEF format instead of the format that the default masm prototypes are written in.

It produces a shorter API call but duplicates that call every time so that commonly used APIs like SendMessage() end up generating more code. MASM by default builds the standard PROTOYPE format that produces a lookup table at the end of the binary file and this has some to do with MASM's primary purpose of writing VXD and later format drivers.

The form created by L2EXTIA.EXE produces calls in much the same way as VC. It is there so that people who are interested have the choice in how their binary code is generated.


Posted on 2002-07-18 22:11:52 by hutch--

Thanks for the clearification.
I guess when code size and/or execution speed become an issue I will look into the tools more.


ps- U sure u cant join my Java Virtual Machine project ?
Posted on 2002-07-19 00:53:33 by James_Ladd

ps- U sure u cant join my Java Virtual Machine project ?

Old... ermm... Experienced hutch and JAVA? Dont.think.he.likes.the.syntax :)

Better ask at www.RentACoder.com ;)
Posted on 2002-07-19 01:17:10 by bazik

Hutch would not have to do java, just some of the virtual machine. Like garbage collection, byte code execution and other really interesting bits. Of course I would be doing as much of it as I can.

Pitty u cant help. What was that "un-named" language you were working on ?

Posted on 2002-07-19 01:26:25 by James_Ladd