News:

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

Link.exe expecting symbols with _prefixed

Started by madhur_ahuja, December 03, 2010, 04:21:26 AM

Previous topic - Next topic

madhur_ahuja

Quote from: MichaelW on December 04, 2010, 06:12:39 AM
What a mess. The file io.asm looks like some code I have by Richard Detmer, that has the same right to left parameter order. The Detmer examples specify:

.model flat, stdcall

And work out the difference with a set of interface macros.


I only see .MODEL FLAT in my version.

MichaelW

Quote from: madhur_ahuja on December 04, 2010, 06:14:54 AM
I only see .MODEL FLAT in my version.

Yes, now that I check I had added the stdcall (in 2004).
eschew obfuscation

japheth


The thread is a mess.

I don't think that it's a good idea to modify the sources. As you said, they are from a book, so it almost certainly once DID work. The sample uses the ".model flat" directive ( which tells me that they are intended for Masm v6.xx ), so everything should work without changes if you use Masm v6.14 included in Masm32.

The problem mentioned in the first post is a "name decoration" problem. Most likely it occurs because  an option (-Gd) was missing in the command line when Masm was launched.

Btw, the io.inc which you posted still lacks the "output" macro, which is used in hello.asm, so it is of little help.

MichaelW

The "output" macro is there - it's just hard to see because the name is tabbed over to the position of the code. After I sorted out the paths in hello.asm:

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include io.inc
.LISTALL
includelib \masm32\lib\kernel32.lib


I assembled, linked, and tested with this batch file:

@echo off
set file1="io"
set file2="hello"
set lib=c:\masm32\lib
set path=c:\masm32\bin;%path%
if exist %file1%.obj del %file1%.obj
if exist %file2%.obj del %file2%.obj
if exist %file2%.exe del %file2%.exe
ml /c /coff %file1%.asm
pause
ml /c /coff %file2%.asm
pause
Link /SUBSYSTEM:CONSOLE %file2%.obj %file1%.obj
pause
%file2%.exe
echo.
echo.
pause


And there were no problems.
eschew obfuscation

japheth

Quote from: MichaelW on December 04, 2010, 07:12:37 AM
The "output" macro is there - it's just hard to see because the name is tabbed over to the position of the code.
...
And there were no problems.

Thanks! Yes, no problems. And I additionally tried to remove the "_"-prefixes in io.asm and assembled it with the -Gd option: this also works.

madhur_ahuja

Thanks guys. Either specifying -Gd or using .model flat, stdcall solves the problem.

However, I believe -Gd means C style function calling and naming conventions as per
http://msdn.microsoft.com/en-us/library/s0ksfwcf.aspx

But I don't see stack being cleaned up by caller as specified in:
http://en.wikipedia.org/wiki/X86_calling_conventions

Am I missing something ?

MichaelW

For a procedure that uses the C calling convention ML would encode the return instruction to not remove the parameters from the stack, and invoke would add code to remove the parameters from the stack after the call returned. In my tests with ML6.15, and a STDCALL procedure, -Gd did affect the naming convention, but did not affect the encoding of the return instruction or the calling convention that invoke assumed.
eschew obfuscation

donkey

Quote from: madhur_ahuja on December 04, 2010, 07:52:34 AM
But I don't see stack being cleaned up by caller as specified in:
http://en.wikipedia.org/wiki/X86_calling_conventions

Am I missing something ?

He has explicitly made the procedures into STDCALL by using RET with a value, this will adjust the stack by the number of bytes specified, for example in the _dtoaproc his return is ret 8 which will add 8 to ESP before returning.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

BASIC uses this calling convention - reverse parm order, but corrects the stack as in STDCALL

anyways, this is some old stuff - lol
if this is for school, you may not have any choice but to work with it
but, if you are trying to learn masm from a book (on your own), i suggest you get some new stuff
this library can create some bad habits for you

all registers are preserved and the math procs set the flags to indicate the results
very few modern procs work that way
the worst thing is, some procs use word-sized parms
for modern code that uses word parms, dwords are passed to maintain stack alignment

if you modify the procs to be up to date, then much of the example code in the book will not work

madhur_ahuja

Yes, this is for self learning and not a school. Can you suggest some other reference ?

dedndave

truthfully, you do not need to buy a book
install the masm32 package
the package contains macros, libraries,  example code, help files, tutorials
the link is in the upper right hand corner of the forum
also in those links, you will find Iczelion's Tutorials - a great way to get started for win32

EDIT
have a look around in those links - a lot of material
another thing you will find in there is a link to Intel Programmer's Reference Manuals
that will cover the instruction set

also - Randy Hyde has a nice online reference....
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html