<<< M09.ASM | Index | Portability Concerns >>> |
The EXTERN MASM directive,
EXTERN _Beep@8:NEAR
defines a program symbol _Beep@8 with a NEAR type, which is needed by the assembler to generate the appropriate CALL instruction.
The linker also gets the kernel32.lib object library on command line:
link /subsystem:console /entry:main /out:M09.exe M09.OBJ kernel32.lib
The library provides the actual binary definition of the Beep system function.
Almost all Windows system functions use __stdcall calling convention . The system function removes its own arguments from the stack.
The __stdcall convention also requires a
function name prefixed by _underscore, and
appended function name suffix @, followed by the decimal number of bytes in the argument list. For example,
EXTERN _Beep@8:NEAR ; Function uses two DWORD arguments EXTERN _GetLastError@0:NEAR ; Function has no arguments .. call _Beep@8 call _GetLastError@0
Under __stdcall convention, function arguments are passed on the stack in right to left order. Download cjumpcxx.exe program, and click
Functions -> Stack Frames
to view animation of the function call.
Please note that M09.BAT demo program is a hack. It pretends to be both Windows batch command file and an assembly program at the same time:
The file has .BAT file extension instead of a typical .ASM
The code begins with a "goto" statement that directs batch command interpreter to the label ":masm". Batch interpreter is oblivious to the semicolons that are comment symbols for the Assembler.
Assembly program follows.
Assembly does not care about any text after the "END" directive.
The rest of the batch commands follow the END.
Now you can double click on the M09.EXE file to compile the M09.EXE program:
The program is assembled and linked in the same directory where the M09.BAT is located.
I am using this hack in the classroom because I need to assemble the demo code as quickly as possible.
<<< M09.ASM | Index | Portability Concerns >>> |