HELP: Getting Error On 1st Attempt To Get MASM32 Working

Started by w1smc, January 31, 2010, 02:31:32 AM

Previous topic - Next topic

w1smc

I tried to assemble & link the following code I pulled from the 80x86 Assembly Language and Computer Architecture book I'm using

.586
.MODEL FLAT

.STACK 4096

.DATA
number  DWORD   -105
sum     DWORD   ?

.CODE
main    PROC
        mov     eax,    number
        add     eax,    158
        mov     sum,    eax

        mov     eax,    0
        ret
main    ENDP

END

and I'm getting the following error.

Any ideas what I'm doing wrong?  Incorrect setup of MASM32? 


*******************************************


Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\savefiles\projects\Assembler\MASM32\project001\test002.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _mainCRTStartup
test002.exe : fatal error LNK1120: 1 unresolved externals
_
Link error
Press any key to continue . . .

dedndave

there should be no stack declaration in a 32-bit program
if you have the masm32 package installed, refer to the masm32\include\masm32rt.inc file for the startup stuff
this is the basics to write simple programs...

      .486
      .model flat, stdcall
      option casemap:none

      include \masm32\include\windows.inc

      include \masm32\include\kernel32.inc
      include \masm32\include\shell32.inc

      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\shell32.lib

also, in 32-bit code, we need to use an API function to terminate a program - not a RET
the code you have looks like it may be intended for 16-bit code

        INVOKE  ExitProcess,0    ;exit code

are you planning on learning 16-bit or 32-bit ?

EDIT - oh - one more thing
the END directive should indicate the entry point
in your case...

        END     main

dedndave

a couple notes, Steve
first, these posts would be better catagorized in the campus sub-forum
this one is really more or less for development of the masm32 project

second, 16-bit code and 32-bit code are quite different
also, 16-bit code is kind of becoming obsolete - some will say it already is
but, seeing as i know 16-bit code better than 32-bit, it isn't obsolete for me - lol
at any rate, if you want to learn "modern" code, 32-bit is the way to go
it lets you create programs that use windows graphical user interface, whereas 16-bit code does not

for 32-bit, many of us started out with Iczelion's tutorial...
http://website.masm32.com/iczelion/iczelion.zip
in the upper right corner of the forum, there are links for other downloads, as well
things like the intel programmers reference manuals, etc are also handy tools to have

there is also the fairly new 64-bit world
newer processors and operating systems support 64-bit
i would say it is still in the stage of infancy, as the programming tools that are available for 32-bit aren't there yet
for someone new to assembler, i would not suggest starting with 64-bit code

w1smc

Dave,

Thanks for the info.

Never a dull moment huh?

I'm more interested in 32 bit coding (for now).

I'll swing over to Iczelions and see what's cookin over there.

We all have to start someplace ...

Thanks again.

w1smc

btw .....

I made the changes you requested and it ran fine .......

Thanks Dave

dedndave

on this post, i have attached some code...
http://www.masm32.com/board/index.php?topic=12621.msg97236#msg97236
i might have put batch files in there too - don't remember

for most programs, you can just use this one line to do all the preliminary stuff...

        INCLUDE \masm32\include\masm32rt.inc

that has the effect of adding all the text in that file into your assembler text file - saves a lot of typing
you can examine that file to see what it does
quite often, you may want to modify the setup and/or add additional libs
a more complex program might start off like this

        INCLUDE \masm32\include\masm32rt.inc
        .586
        INCLUDE    c:\masm32\include\advapi32.inc
        INCLUDELIB c:\masm32\lib\advapi32.lib

certain instructions (like CPUID) require the higher processor
the advapi32 library has the functions needed to read and write to the system registry

you could modify the masm32rt.inc file and add those things
but, if you do that, then post code in the forum, noone else will be able to assemble it because they don't have the same mods
best to keep the masm32 inc/macro/lib files in their original state unless it is required to fix a bug or something

another goodie is to look inside the masm32\help folder
there is one in particular - hlhelp - that has the masm32 macros in it (saves more typing)

the masm32\tutorial and masm32\examples folders have a lot of learning tools as well
the forum search tool is another friend
a lot of very experienced programmers have posted/attached code examples to show you how to do difficult things
in many cases, they have written complete libraries or routines that are fast and well-commented