I have a super simple .ASM file:

.486
.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

.code
main:
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 ?
Regs,
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
directly.
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 ?

Regs,
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]


Source:



Format PE GUI 4.0

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

stdcall [ExitProcess], 0

section '.idata' import data readable writeable

library kernel, 'KERNEL32.DLL'
kernel:
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
bAZiK,

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

bAZiK,

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
Sven,

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

Regards,

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



Disassembly

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


Just used the headers generated by L2EXTIA.EXE

Regards,

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


BIN
#COM
*#DBERROR
*#DBSHOW
#EXAMPLE1
#EXAMPLE2
#EXAMPLE3
#EXAMPLE4
#EXAMPLE5
#EXAMPLE6
#EXAMPLE7
#EXAMPLE8
*HELP
*HTML
#ICZTUTES
INCLUDE
*L2EXTIA
LIB
LICENCE
M32LIB
MACROS
#oop
#PLUGINS
#PROCS
#TEMPLATE
*#VKDEBUG


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
Sven,

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:

Regards,

hutch@movsd.com
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 ?

Regs,
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
James,

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.

Regards,

hutch@movsd.com
Posted on 2002-07-18 22:11:52 by hutch--
Hutch,

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

Regs,

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
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 ?

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