News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

hello world how to compile and link??

Started by marla, February 17, 2006, 06:14:41 PM

Previous topic - Next topic

marla

new to using masm; i am using the qeditor. console assemble and link does not do anything (does not produce output nor create files in the working directory etc. i guess that ml.exe is not a registered executable, so i decide to make a batch file for my commands to link this asm file. the following is my batch file.

ML /c /coff /Cp /nologo /I\masm32\Include one.asm
LINK /SUBSYSTEM:CONSOLE /RELEASE /VERSION:4.0 /LIBPATH:"\masm32\lib" *.obj

i run it from my code directory on my desktop, ML.exe is not recognized.
i try running that from my masm32 directory. ml is not recognized.
ok, so i try it from /lib where ml.exe is there. then i get the errors:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\masm32\bin>make.bat

C:\masm32\bin>ML /c /coff /Cp /nologo /I\masm32\Include one.asm
Assembling: one.asm
one.asm(37) : error A2008: syntax error : print
one.asm(38) : error A2206: missing operator in expression

C:\masm32\bin>LINK /SUBSYSTEM:CONSOLE /RELEASE /VERSION:4.0 /LIBPATH:"\masm32\li
b" *.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : warning LNK4001: no object files specified; libraries used
LINK : warning LNK4068: /MACHINE not specified; defaulting to IX86
LINK : fatal error LNK1159: no output file specified

C:\masm32\bin>

i do not think that it is the code: what the hell is wrong?
:(



;-----------------
; one.asm
;-----------------

.486
.model flat, stdcall
option casemap:none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\masm32.inc
      include \MASM32\INCLUDE\user32.inc
      include \MASM32\INCLUDE\wsock32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\gdi32.inc

includelib \MASM32\LIB\masm32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\wsock32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\gdi32.lib

;-----------------

.data

;-----------------

.data?

;-----------------

.code

start:
print chr$(" one.exe ",13,10)
invoke ExitProcess NULL
end start

;-----------------
;
;
;
;


Vortex

Here is the batch file to build the project :

\masm32\bin\ml /c /coff one.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE one.obj


If you wish, you can use MS link instead of Polink.

I corrected your source file, there is no any comma symbol separating ExitProcess and NULL in your code.

[attachment deleted by admin]

marla

ok i tried using that, but now i am up to the console tutorial now. i fixed the exit process. i really like keeping my code on my thumb drive and not in the C:\masm32\ directory. so i tried hard coding the inc files location and the ml.exe and polink.exe files into the batch file and the asm file.

here is my code:



;-----------------
; one.asm
;-----------------

.486
.model flat, stdcall

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
      include C:\MASM32\INCLUDE\wsock32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\wsock32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

;-----------------

show_txt PROTO :DWORD

;-----------------

.data
splash   DB   "one.exe\n",0
splash2  DB   " Please make a selection ... \n",0

;-----------------

.data?

;-----------------

.code

;-----------------

start:
call main     
invoke ExitProcess,0

;-----------------

main proc
LOCAL txt_input:DWORD
mov txt_input, input("please enter your selection : ")
invoke show_text, txt_input
ret
main endp

;-----------------

show_text proc string:DWORD
print chr$("this is the selection that you made",13,10," --- ")
print string
print chr$(" ---",13,10)
ret
show_text endp

;-----------------

end start

;-----------------
;
;
;
;


here is my batch file:

c:\masm32\bin\ml /c /coff one.asm
c:\masm32\bin\polink /SUBSYSTEM:CONSOLE one.obj

here are my errors:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Z:\asm>make.bat

Z:\asm>c:\masm32\bin\ml /c /coff one.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: one.asm
C:\MASM32\INCLUDE\windows.inc(115) : error A2004: symbol type conflict : bool
C:\MASM32\INCLUDE\windows.inc(8052) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8052) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8064) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8064) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8082) : error A2005: symbol redefinition : hinst
C:\MASM32\INCLUDE\windows.inc(8772) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8772) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8779) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8779) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8784) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8784) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8790) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8790) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8797) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8797) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8807) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8807) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8813) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8813) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(8820) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(8820) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9066) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9066) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9954) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9954) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9967) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9967) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9979) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9979) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9984) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9984) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9989) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9989) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9994) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9994) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(9999) : error A2179: structure improperly initiali
zed
C:\MASM32\INCLUDE\windows.inc(9999) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10006) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10006) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10013) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10013) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10020) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10020) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10025) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10025) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10031) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10031) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10039) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10039) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10040) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10040) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10044) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10044) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10050) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10050) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10057) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10057) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10064) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10064) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10069) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10069) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10077) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10077) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10084) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10084) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10092) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10092) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10099) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10099) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10109) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10109) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10110) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10110) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10114) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10114) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10115) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10115) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10120) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10120) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10126) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10126) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10133) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10133) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10140) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10140) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10146) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10146) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10157) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10157) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10165) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10165) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10176) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10176) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10188) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10188) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10196) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10196) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10204) : error A2179: structure improperly initial
ized
C:\MASM32\INCLUDE\windows.inc(10204) : error A2008: syntax error : in structure
C:\MASM32\INCLUDE\windows.inc(10215) : fatal error A1012: error count exceeds 10
0; stopping assembly

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE one.obj
POLINK: fatal error: File not found: 'one.obj'.

Z:\asm>

..........

i cannot seem to fix this, thanks in advance.

MichaelW

You must include a "option casemap :none" statement because windows.inc depends on case sensitivity. For example, the first error you are seeing is due to these two definitions in windows.inc:

BOOL typedef DWORD
bool typedef BYTE


And the second is due to this structure definition:

LUID_AND_ATTRIBUTES STRUCT
    Luid LUID <>
    Attributes dd ?
LUID_AND_ATTRIBUTES ENDS

eschew obfuscation

hutch--

marla,

As long as your installation of MASM32 is not broken, it will build all of its own console mode examples with no problems. To see how its done, look at the batch files in the BIN directory. Most of your problems are incorrect command line options or path errors. ML.EXE is a normal command line application that is not set up in windows with any special considerations so you must always supply it the correct path for the target.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

marla

hutch, guys: i fixed the casemap, the batch script is fine i think - i am using an almost exact copy of the console tutorial in the masm 32 dir.

here is my only error now:

Z:\asm>c:\masm32\bin\ml /c /coff one.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: one.asm
one.asm(52) : error A2006: undefined symbol : show_text

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE one.obj
POLINK: fatal error: File not found: 'one.obj'.

here is my current code:




;-----------------
; one.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

;-----------------

show_txt PROTO :DWORD

;-----------------

.data
splash   DB   "one.exe\n",0
splash2  DB   " Please make a selection ... \n",0

;-----------------

.data?

;-----------------

.code

;-----------------

start:
call main     
invoke ExitProcess,0

;-----------------

main proc
LOCAL txt_input:DWORD
mov txt_input, input("please enter your selection : ")
invoke show_text, txt_input
ret
main endp

;-----------------

show_text proc string:DWORD
print chr$("this is the selection that you made",13,10," --- ")
print string
print chr$(" ---",13,10)
ret
show_text endp

;-----------------

end start

;-----------------
;
;
;
;


no idea what is wrong now with the code ...

Ian_B

Try a comma after "show_text proc" before the parameter list "string:DWORD". That should clear it up, you PROTO'd it fine.

IanB

marla


i added the comma, still the same error. perhaps i should have show_txt PROTO :DWORD somewhere else than on the top


;-----------------
; one.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

;-----------------

show_txt PROTO :DWORD

;-----------------

.data
splash   DB   "one.exe\n",0
splash2  DB   " Please make a selection ... \n",0

;-----------------

.data?

;-----------------

.code

;-----------------

start:
call main     
invoke ExitProcess,0

;-----------------

main proc
LOCAL txt_input:DWORD
mov txt_input, input("please enter your selection : ")
invoke show_text, txt_input
ret
main endp

;-----------------

show_text proc, string:DWORD
print chr$("this is the selection that you made",13,10," --- ")
print string
print chr$(" ---",13,10)
ret
show_text endp

;-----------------

end start

;-----------------
;
;
;
;

MichaelW

Quote
one.asm(52) : error A2006: undefined symbol : show_text
Here is line 52:

invoke show_text, txt_input

Here is the definition of show_text on line 58:

show_text proc string:DWORD

Because invoke does not support forward references, on line 52 show_text is effectively undefined. To correct this you should place either the procedure definition or a procedure prototype somewhere above the invoke statement. For the prototype on line 25 the procedure name is show_txt instead of show_text.

eschew obfuscation

marla

i fixed the error in the spelling, now i get:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

Z:\asm>make.bat

Z:\asm>c:\masm32\bin\ml /c /coff one.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: one.asm

Z:\asm>c:\masm32\bin\polink /SUBSYSTEM:CONSOLE one.obj
POLINK: error: Unresolved external symbol '_show_txt'.
POLINK: fatal error: 1 unresolved external(s).

Z:\asm>

but the thing is: i am copying code right offo f the console example in the tutorials. i do not understand how to fix this...



;-----------------
; one.asm
;-----------------

.486
.model flat, stdcall
option casemap :none

include C:\MASM32\INCLUDE\windows.inc
      include C:\masm32\macros\macros.asm
include C:\MASM32\INCLUDE\masm32.inc
      include C:\MASM32\INCLUDE\user32.inc
include C:\MASM32\INCLUDE\kernel32.inc
include C:\MASM32\INCLUDE\gdi32.inc

includelib C:\MASM32\LIB\masm32.lib
includelib C:\MASM32\LIB\user32.lib
includelib C:\MASM32\LIB\kernel32.lib
includelib C:\MASM32\LIB\gdi32.lib

;-----------------

show_txt PROTO :DWORD

;-----------------

.data
splash   DB   "one.exe\n",0
splash2  DB   " Please make a selection ... \n",0

;-----------------

.data?

;-----------------

.code

;-----------------

start:
call main     
invoke ExitProcess,0

;-----------------

main proc
LOCAL txt_input:DWORD
mov txt_input, input("please enter your selection : ")
invoke show_txt, txt_input
ret
main endp

;-----------------

show_text proc, string:DWORD
print chr$("this is the selection that you made",13,10," --- ")
print string
print chr$(" ---",13,10)
ret
show_text endp

;-----------------

end start

;-----------------
;
;
;
;

zooba

Quote from: marlashow_text proc, string:DWORD

The comma isn't required here. :U

Ian_B

The comma should be right, surely?  :eek

Michael's right, he still has two "show_txt" references and a "show_text". You need to make them all match, wherever they occur, either with an E or without.  :U

IanB

hutch--

Change your source code to,


show_text PROTO :DWORD

from

show_txt PROTO :DWORD


It builds fine as it is once this is fixed.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php