Hi all,
First of all I downloaded the masm32 from http://www.masm32.com/masmdl.htm (http://www.masm32.com/masmdl.htm) and it installed successfully in my windows 7 machine. After that I was able to load some examples with the quick editor and running them.
But the thing is that Im trying to learn assembly with the book "Guide to assembly" author James T. Streib, and simply cant compile the first program example:
.386
.model flat, c
.stack 100h
.data
num1 sdword ? ; first number
num2 sdword ? ; second number
.code
main proc
mov num1,5 ; initialize num1 with 5
mov eax,num1 ; load eax with contents of num1
mov num2,eax ; store eax in num2
ret
main endp
end
The code is converted to .obj, but I get the following error from the linker:
LINK:error LNK2001: unresolved external symbol _mainCRTStartup
Is there a solution for this? Or is there something Im missing?
I've seen that all the examples in the forum have library declarations, I dont know if it has to do with it.
By the way, the code above is in the bin directory of masm32.
Sorry but Im a total noob in the subject. Thanx.
it's 16-bit code and a 16-bit book in a win32 world
you can use Link16.exe, rather than Line.exe to link 16-bit programs
better to get a different book
or no book at all - the info you need is available online
Thanx dedndave for your answer.
Well, Im getting more cofused then, how can it be a 16 bit code, when the author claims to teach 32 bit code? Also, he is using extended registrers, thats from the 32 bit world, isn it?
Thanx fro your time.
sorry about that
we get that mistake so often in here, i didn't look very closely at the code - lol
what seems to be missing is the entry point
also - in win32, flat model - no stack declaration is required
(when i saw stack, i assumed 16-bit code)
.386
.model flat, c
.data
num1 sdword ? ; first number
num2 sdword ? ; second number
.code
main proc
mov num1,5 ; initialize num1 with 5
mov eax,num1 ; load eax with contents of num1
mov num2,eax ; store eax in num2
ret
main endp
end main ;entry point in END statement
as a side note....
you can use 32-bit registers in 16-bit (DOS) code
what makes it 16 or 32 bit is the segment type
the assembler and linker create addresses of the proper size
of course, the OBJ and EXE files also have different formats
now that you've had a little time to play with that, try this one...
include \masm32\include\masm32rt.inc
.data
num1 sdword ? ; first number
num2 sdword ? ; second number
.code
main proc
mov num1,5 ; initialize num1 with 5
mov eax,num1 ; load eax with contents of num1
mov num2,eax ; store eax in num2
print uhex$(num1),13,10
print uhex$(num2),13,10
inkey
exit
main endp
end main
it creates an EXE that you can run in a console window
Wow thanx, my programs now runs fine, and the last example is wonderful.
Well but that is strange, why the print function does not need "invoke"?.
For example the Hellow world program that use stdout needs to use invoke:
include \masm32\include\masm32rt.inc
.data
HelloWorld db "Hello World!",13,10,0
.code
main proc
invoke StdOut, addr HelloWorld
inkey "Press a key to continue ..."
invoke ExitProcess, 0
main endp
end main
Quote from: Zaratustra on May 23, 2014, 03:16:20 PM
Well but that is strange, why the print function does not need "invoke"?.
Because print is not a function, it's a macro:
print MACRO arg1:REQ,varname:VARARG ;; display zero terminated string
IFNDEF __UNICODE__
invoke StdOut,expand_prefix(reparg(arg1))
ELSE
invoke StdOutW,expand_prefix(reparg(arg1))
ENDIF
IFNB <varname>
IFNDEF __UNICODE__
invoke StdOut,chr$(varname)
ELSE
invoke StdOutW,chr$(varname)
ENDIF
ENDIF
ENDM
See \masm32\macros\macros.asm, which defines ~120 macros currently.
sorry - i should have spent a little more time explaining that
i was tired, and went to bed
uhex$ and exit are also macros that may be looked up, as Michael suggested
i learned a lot by looking up the macros and functions to see how they are written
so, besides the macros.asm file that Michael mentioned,
there are also several files in \masm32\m32lib worth looking over
it's great to use them - but even better to understand what's going on underneath
Quote from: dedndave on May 24, 2014, 03:01:31 AM
it's great to use them - but even better to understand what's going on underneath
That's absolutely right. And welcome to the forum, Zaratustra.
Gunther
Thanx for your answers, they are relly helpful.
Thats right, I realize the thing about macros a little bit later, I will continue my quest in learning assembly and of course once I get more confortable with the subject I will take a look at the functions and macros.