The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: emerald-monk on January 09, 2020, 04:47:17 AM

Title: Error while Building the program
Post by: emerald-monk on January 09, 2020, 04:47:17 AM
Hi!!
I'm new to assembly language and I'm trying to build a small program that prints "A" character. However when I'm trying to build the code from Project >> Build All, I'm getting the following error:

LINK : error LNK2001: unresolved external symbol _main
temp.exe : fatal error LNK1120: 1 unresolved externals
Link error...

Here is my piece of code:
dosseg
.model small
.stack 100h
.data
.code
main proc
    mov dl, 'A'
    mov ah, 2
    int 21h
    mov ah, 4ch
    int 21h
    main endp
end Main

can anyone help me on how to resolve this please??
Title: Re: Error while Building the program
Post by: jj2007 on January 09, 2020, 05:12:54 AM
It works fine over here. What kind of error messages do you get?

Follow these steps:
- extract the attached file to \Masm32\BldRun16.bat
- modify \Masm32\menus.ini:
...
Build+Run 16-bit,\MASM32\BldRun16.bat "{b}"

[&Tools]

- open your source in qEditor, save as test.asm (for example) and click Project/Build+Run 16-bit

If you get an error about incompatibility etc, it means you have a 64-bit OS that won't run 16-bit programs. Go to this page (http://takeda-toshiya.my.coocan.jp/) and download Binaries and Source Codes (i86/i286/i386/i486) (http://takeda-toshiya.my.coocan.jp/msdos/msdos.zip)

Since that page right now has a problem, you may also use the older attached version. Extract to \Masm32\bin\msdos.exe
Title: Re: Error while Building the program
Post by: mineiro on January 09, 2020, 05:58:14 AM
hello sir emerald-monk;
This can be solved by some ways, but I prefer talk to you do that by hands.
I'm not sure what IDE you're using, so, the assemble and link command line are hidden. Do this by hands instead of "build all".

If you're impatience, you can try insert before main proc the line below:
public main

Other thing you can try is remove "main proc" and "endp" and insert in the place of "main proc" the line below:
main:

Can you see that the error link "renamed" your "main" to "_main"? This is probably because the linker is trying to link that as a "c" style in easy words, or ... .
This code is done to ms-dos 16 bits, by default I'm assuming your IDE is trying to assemble and link that to 32 bits.

ps: try what sir jj2007 posted previously.
Good job.
Title: Re: Error while Building the program
Post by: aw27 on January 09, 2020, 06:31:26 AM
\masm32\bin\ML6 -c test.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: test.asm

\masm32\bin\link16 test.obj, test.exe,0,0,nul.def

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

(https://www.dropbox.com/s/ahsktab6py8ya9h/dosbox.png?dl=1)
Title: Re: Error while Building the program
Post by: emerald-monk on January 09, 2020, 10:26:06 PM
Hi!! Everyone, i'm using IDE from www.masm32.com/download.htm

I'm trying to fix the problem but i can't seem to find the settings/configuration/preferences page where I can check what the problem is.

Thanks & Regards
Title: Re: Error while Building the program
Post by: aw27 on January 09, 2020, 11:23:44 PM
The IDE is not important, people in the DOS era used Edlin or Edit or even con

con is the easiest here.

c:\type con > test.asm
dosseg
.model small
.stack 100h
.data
.code
main proc
    mov dl, 'A'
    mov ah, 2
    int 21h
    mov ah, 4ch
    int 21h
    main endp
end Main
^Z

Build with the tools, as explained above.

What you don't know is the syntax of the tools needed to build the program and can't figure out from the supplied examples. This is the serious problem.
Title: Re: Error while Building the program
Post by: mineiro on January 10, 2020, 01:44:36 AM
AW, I remember echo too to redirect to a file.
"Programming in extreme conditions" article by Kalmykov.b52
We can also do that by using Paint Shop Pro, Photoshop, hexadecimal colors, debug, ... .

emerald-monk;
You need do that by hands.
Have archieved old board with tons of examples, a lot of command lines to be used in 16 bits DOS programming.
Check your assembler and link version.
http://www.masmforum.com/board/index.php
Title: Re: Error while Building the program
Post by: aw27 on January 10, 2020, 03:05:08 AM
Quote
AW, I remember echo too to redirect to a file.
"Programming in extreme conditions" article by Kalmykov.b52
We can also do that by using Paint Shop Pro, Photoshop, hexadecimal colors, debug, ... .

@mineiro  :biggrin:
Title: Re: Error while Building the program
Post by: jj2007 on January 10, 2020, 03:15:26 AM
Quote from: emerald-monk on January 09, 2020, 10:26:06 PM
I'm trying to fix the problem but i can't seem to find the settings/configuration/preferences page where I can check what the problem is.

Just read my post above carefully, it will solve your problem.
Title: Re: Error while Building the program
Post by: TimoVJL on January 10, 2020, 06:39:31 AM
If you know something about C, check this toy.
TLIDE (http://masm32.com/board/index.php?topic=7483.msg81793#msg81793)

ccpath: \masm32\bin\ml.exe
link: \masm32\bin\link16.exe