News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Some basic help

Started by LoveToLrn, December 04, 2013, 02:08:00 PM

Previous topic - Next topic

LoveToLrn

Hi Guys! I am new to the forum and MASM32 development environment but I am loving it and the community on this forum already.
My question pertains mainly to a problem I am having with assembling and linking basic programs. For some reason when I try to
"Console Assemble and Link" the following code, I get this error:

"error LNK2001: unresolved external symbol _main"



code:
Quote
.486
.MODEL flat

.code
main:
    mov eax,0FFFFFFFFh
END main
I have been able to get other examples to run, but for some reason these basic ones won't link.
I am trying to focus on 32-bit code currently. I am coming from writing my basic assembly programs in Visual Studio 2012.
Any help is appreciated, Thanks in advance everyone!

Siekmanski

Welcome  LoveToLrn,


    .486
    .model      flat,stdcall
    option      casemap:none

    include     windows.inc
    include     user32.inc
    includelib  user32.lib
    include     kernel32.inc
    includelib  kernel32.lib

.data
; your data here

.code
; your subroutines here

start: ; starting point of your program

    invoke  ExitProcess,0
end start


Have you downloaded the masm32 SDK?  http://masm32.com/masmdl.htm
It has a lot of examples.
Creative coders use backward thinking techniques as a strategy.

LoveToLrn

Yes I downloaded the whole package I believe. I wasen't sure if I was missing any "mission critical" code like those includes,
looking at them I can see what I missed, thanks very much Siekmanski!  :biggrin:

dedndave

that specific error is probably related to the missing line
  .MODEL Flat,StdCall

terminating with ExitProcess is also a nice idea
but, i can understand what you were doing - you eliminated all the externals

the processor, model, casemap option, and includes can all be done with one line
    INCLUDE     \Masm32\Include\Masm32Rt.inc
that is a plain ASCII text file that you can open and examine with NotePad
it covers the most-often used includes and libraries

LoveToLrn

OH! Thanks for the tip dedndave! Can I modify the text file with my own libs/includes?

dedndave

you can, but i don't recommend it   :eusa_naughty:

dedndave

just add any additional includes and/or includelibs after that line
    INCLUDE     \Masm32\Include\Masm32Rt.inc
    .586
    INCLUDE     \Masm32\Include\AdvApi32.inc
    INCLUDELIB  \Masm32\Lib\AdvApi32.lib


and - anything that's in there that your program does not use won't affect the size of the EXE

the reason i don't recommend it.....

you won't be compatible with all the code posted in the forum
when someone else tries to build your project - bang - errors
same when you try to build someone else's

EDIT: i also added a bump in the processor from 486 to 586

LoveToLrn

Ok, good point, thanks  :biggrin:
Also is your .586 directive just a more recent version of the processor model than .386, or .486 for that matter?
Is there any benefit to specifying a more recent processor model number beyond .386?

dedndave

yes there is
it allows you to use the newer pentium instructions and instruction forms
one example that comes to mind is the RDTSC instruction, but there are others

also, if you want to use SIMD instructions....
    .686
    .MMX
    .XMM


i think the masm version that is in the masm32 package goes as far as SSE2 extensions
you can find newer versions of the assembler that can handle SSE3, 4, etc
also, JwAsm is a free assembler that handles them and is nearly 100% compatible with masm

LoveToLrn

Awesome, Thanks for the info!
I am not as far along as SIMD but hope to be writing more complex programs soon.
I think you guys and this forum as a whole will be a HUGE boost! Very glad I found it. :biggrin:

dedndave

try this program
assemble as console mode
        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

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

;initialized data section

        .DATA

szMessage db 'Hello World !',0

;***********************************************************************************************

;uninitialized data section

        .DATA?

dwSomeVal dd ?

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

;code section

        .CODE

;***********************************************************************************************

_main   PROC

        print   offset szMessage

        print   chr$(13,10)
        inkey
        INVOKE  ExitProcess,0

_main   ENDP

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

        END     _main

LoveToLrn

I tried it out, I was wondering how to pass a wait message to the console! Thanks  :biggrin:
Also didn't know there was a .data segment for uninitialized variables.

hamper

Quote from: LoveToLrn on December 04, 2013, 03:36:07 PM
Also didn't know there was a .data segment for uninitialized variables.
There isn't. The data segments are...

.const
Here you define any global constant data such as integer constants, string constants and floating point constants etc.

.data?
Here you define uninitialised global variables such as general variables, arrays and structures etc. Memory is reserved but not initialised.

.data
Here you define initialised global variables such as general variables, arrays and structures etc. Memory is reserved and initialised.

jj2007

Quote from: hamper on December 04, 2013, 10:39:50 PM
.data?
Here you define uninitialised global variables such as general variables, arrays and structures etc. Memory is reserved but not initialised.

That is the "official" version. Truth is the OS initialises them to zero - in contrast to local variables, which are really not initialised, i.e. a space is reserved for them on the stack, but it will contain garbage.

hamper

I knew that was the situation under C, where uninitialised global variables are automatically initialised to zero (for numeric) or nul (each byte of a character or string), and uninitialised local variables of any type are not automatically initialised at all (so their memory locations will still contain whatever was there already), but I didn't know whether this was the case under assembly language as well. Guess I'll have to check this out and update my notes accordingly. Thanks for the info.