Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Problem linking trivial program in Windows
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 26th March 00:31
riley dewiley
External User
 
Posts: 1
Default Problem linking trivial program in Windows



I am new to assembler (well, sort of, used it a while back) and totally new
to Windows assembler.

I am trying to assemble and link a null, 'bread sandwich' program on XP.

I am getting an unresolved external on the _ExitProcess using ML.exe and
LINK.EXE.

I know I need to declare ExitProcess somehow using underscores or name
decoration or whatever.

What is correct syntax? I am using these commands:
ml /c runme.asm

-and-

link runme.obj /implib:import32.lib /subsystem:console

Here is the code:

...386P
extrn _ExitProcess:PROC;

...MODEL Flat, StdCall

...CODE

_Start:

nop

call _ExitProcess

...STACK

END _Start

;;--that's all folks ...
  Reply With Quote


  sponsored links


2 26th March 00:32
kevin g. rhoads
External User
 
Posts: 1
Default Problem linking trivial program in Windows



Use GCC or OpenWatcom to make the same trivial program in C,
and dis-assemble the .OBJ and .EXE. DO it with debugging on
and make sure the linkers put the symbols into either the EXE
or some separate file which you can find.
  Reply With Quote
3 26th March 04:28
betov
External User
 
Posts: 1
Default Problem linking trivial program in Windows


"Riley DeWiley" <spamtrap@crayne.org> écrivait news:4oadnWAlt9FT1kXeRVn-
qw@seanet.com:

Yes.



Betov.

< http://rosasm.org >
  Reply With Quote
4 26th March 04:28
spamtrap
External User
 
Posts: 1
Default Problem linking trivial program in Windows


It's likely to be _ExitProcess@4 (the @4 is to signify that it takes
one dword parameter on the stack). That's certainly what it is using
'nasm' to assemble and 'gcc' to link, anyway.

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.
  Reply With Quote
5 26th March 04:28
mark jones
External User
 
Posts: 1
Default Problem linking trivial program in Windows


Hi Riley. Are you using Hutch's MASM32 package v8.2 SP2? Get the latest version
and upgrade at http://www.masm32.com. New version 9 is in the works. Look in
MASM32\Examples\Example1\MINIMUM for a bare-bones win32 app. Visit the
http://www.masmforum.com usergroup, and be sure to look for the Iczelion tutorials -
those are very good.
  Reply With Quote
6 26th March 04:29
riley dewiley
External User
 
Posts: 1
Default Problem linking trivial program in Windows


Well the syms have __crtExitProcess, ExitProcess, ExitProcess@4,
__imp__ExitProcess@4, none of which seem to work ... ?
  Reply With Quote
7 26th March 12:53
mark jones
External User
 
Posts: 1
Default Problem linking trivial program in Windows


minimum.asm:

; ################################################## #######################

.386
.model flat, stdcall
option casemap :none ; case sensitive

; ################################################## #######################

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:

; alternately you could do this, but file size will increase
; because it creates a PE section for initialized data:
;.data
; szDlgTitle db "Minimum MASM",0
; szMsg db " --- Assembler Pure and Simple --- ",0
;.code

jmp @F
szDlgTitle db "Minimum MASM",0
szMsg db " --- Assembler Pure and Simple --- ",0
@@:

push MB_OK
push offset szDlgTitle
push offset szMsg
push 0
call MessageBox

push 0
call ExitProcess

; --------------------------------------------------------
; The following are the same function calls using MASM
; "invoke" syntax. It is clearer code, it is type checked
; against a function prototype, and is less error-prone.
; --------------------------------------------------------

; invoke MessageBox,0,ADDR szMsg,ADDR szDlgTitle,MB_OK
; invoke ExitProcess,0

end start


build.bat:

@echo off

if exist minimum.obj del minimum.obj
if exist minimum.exe del minimum.exe

\masm32\bin\ml /c /coff /nologo minimum.asm
\masm32\bin\link /SUBSYSTEM:WINDOWS /MERGE:.rdata=.text minimum.obj > nul

dir minimum.*

pause
  Reply With Quote
8 26th March 12:53
tim roberts
External User
 
Posts: 1
Default Problem linking trivial program in Windows


The easiest way is to use the "proto" statement to declare the function,
instead of a plain "extrn". MASM will supply the proper decoration.
C:\Tmp> type x.asm
..586
..model flat, stdcall
ExitProcess proto WORD
..code
_start:
push 0
call ExitProcess
; or:
; invoke ExitProcess, 0 end _start
C:\Tmp>ml /c x.asm
Microsoft (R) Macro Assembler Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: x.asm
C:\Tmp>link /subsystem:console /out:x.exe x.obj kernel32.lib
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Tmp>
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
  Reply With Quote
9 26th March 17:39
mark jones
External User
 
Posts: 1
Default Problem linking trivial program in Windows


Hi Tim. Why not just include Kernel32.inc like most standard apps?
ExitProcess is already defined there.
  Reply With Quote
10 27th March 00:10
tim roberts
External User
 
Posts: 1
Default Problem linking trivial program in Windows


That assumes that you have kernel32.inc, which implies that you have
downloaded and installed MASM32. What I posted works with nothing other
than ml.exe.

(And link.exe, and kernel32.lib...)
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666