News:

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

Linker Troubles - 1190

Started by AceSnoopy, June 16, 2008, 10:07:04 PM

Previous topic - Next topic

AceSnoopy

Ok, im new to the forum - and assembler (hi all  :bg). I admittedly wasn't going to join at first but this is really annoying me now and i can't find a solution anywhere - possibly not least due to some basic misunderstanding on my part, but there you are.

I'm having a ridiculous level of trouble with linking simple projects into final exectuables - i've done this kind of thing before with high level languages and no trouble, but something here escapes me. I'm currently running RadASM, although ive tried the same with microsoft ml.exe and link.exe command line tools from a Visual C++ package with no success, attempting to make a perfectly normal 'hello world' console app. the code is a single file as follows:


.MODEL Small
.STACK 100h
.DATA
   msg db 'Hello, world!$'
.CODE
_start:
   mov ah, 09h
   lea dx, msg ; or mov dx, offset msg
   int 21h
   mov ax,4C00h
   int 21h
end _start


All parameters are default in attempts with both RadASM and ML - and i consistently get a LNK1190 error - detailed invalid fixup error type 0x0001. The microsoft site is veeeeery helpful on the subject (the error page is http://msdn.microsoft.com/en-us/library/ha0f0278.aspx) and i've tried its suggestion of recompiling object files over and over with no result.

Im sure its something obvious i'm doing wrong - anyone? pleeeeez?  :boohoo:

jj2007

This works under Masm32...

.486                                      ; create 32 bit code
.model small, stdcall                      ; 32 bit memory model
      option casemap :none                ; case sensitive
      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib

.STACK 100h
.DATA
   msg db 'Hello, world!$', 0
   msgTitle db "Test", 0
.CODE
start:
   invoke MessageBox, 0, addr msg, addr msgTitle, MB_OK
   invoke ExitProcess, 0
end start

jj2007

If you just want a testbed, here is one. Fully operational Masm32 code...

include \masm32\include\masm32rt.inc

.code
MyText   db "Hello World", 0
AppName   db "Masm32:", 0

start:   invoke MessageBox, NULL, addr MyText, addr AppName, MB_OK
   exit

end start

sinsi

To link old 16-bit DOS programs you need the 16-bit linker from here.
Depending on the version of ML you're using, you might also need the command switch /omf for ML.
Light travels faster than sound, that's why some people seem bright until you hear them.

AceSnoopy

Ok, sorry for the delay in replying - been meddling with things and willing them to work.

@jj2007 - thanks for the code samples, but i still get the same linker errors, still trying different command switches but havent found one that works yet

@sinsi - im using ml 8.00.50727...  with link of the same version. When i try the omf switch with ml, link 8 gives me an invalid object file error - and if i use the 16 bit linker to create, it gives me an executable - but not an altogether wholesome one, which triggers the system speaker for a while and prints gibberish to std out before terminating normally. Note that with LINK 16 im specifying no exe, list file, libraries or definitions...

*sigh* i can put some zips of screenshots and source/object files out there if itd help, but im still flummoxed - thanks for trying though

PBrennick

This definitely works using masm.exe and link16.exe


.model small
.data
msg db 'Hello World!$'
                                                   
                                                   
.code
main proc
     mov ax,@data
     mov ds,ax
     mov ah, 9       
     mov dx, offset msg       
     int 21h
     mov ax,4c00h
     int 21h
main endp
end main



@ECHO OFF
IF NOT EXIST testing.asm GOTO END
IF EXIST testing.exe DEL testing.exe
MASM /W2/Z testing.asm;
IF NOT EXIST testing.obj GOTO END
LINK16 testing.obj;

:LAST
DEL testing.obj
:END


NOTE: because you are not using the TINY model I am assuming you wish to create an EXE. That is what you will get with the above.

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

sinsi

A DOS EXE file needs segment registers set up first - DOS function 9 to print a string needs the address of the string in DS:DX. Your code doesn't initialise DS, so the
address doesn't actually point to your string. Paul's code has the extra bit -

     mov ax,@data
     mov ds,ax

Add that at the start and everything goes OK.


C:\asm>ml8 /omf test16.asm
Microsoft (R) Macro Assembler Version 8.00.50727.104
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: test16.asm

C:\asm>link16 test16;

Microsoft (R) Segmented-Executable Linker  Version 5.10.005
Copyright (C) Microsoft Corp 1984-1989.  All rights reserved.


C:\asm>test16
Hello, world!
C:\asm>

Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

Ace,

The basics are as the guys here have told you, you cannot build a 16 bit dos MZ exe or com file with a 32 bit linker, they construct a different file format. You need the 16 bit linker at the link above as it WILL build any dos code in masm if the code is correct.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Hutch states it well, but, Sinsi - that code that I posted works just fine. I think you are thinking of the .com model which is VERY different from the .exe model. Be careful with your advice.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

sinsi

Paul - the code he posted, with the two lines added, also worked.

Quote from: PBrennick on June 18, 2008, 05:15:58 AM
I think you are thinking of the .com model which is VERY different from the .exe model.
Those two lines are needed for an EXE and not needed for a COM (since a COM file starts with CS=DS=ES=SS=PSP).
Light travels faster than sound, that's why some people seem bright until you hear them.

ChrisLeslie

Hi Paul

I thought that sinsi made it quite clear that he was talking about an .exe model, and that his remarks were intended for AceSnoopy.

Regards

Chris

PBrennick

Sinsi,
Thank you. Never said they would not. All I wanted to point out in as friendly a way as possible is that the tiny model (which is for .com files has very differnet requirements than the others. With the other models, exe2bin will ask for a fix-up. Using the small model, you are not confined to a segment barrier and so the system does not require you to define them, it will do it for you. In the tiny model, if you do not wish to go through all the trouble, you can force the system to do it for you by using the .DOSSEG directive.

Again, the way you posted made it seem you were saying my code does not work, so I got rankled because it does. Sorry mate, I am a little bit sensitive right now.

Where is MichaelW when you need him?  :bg

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

AceSnoopy

 :green2

I've never been so happy to see 'Hello World'! yup i finally got it to work by using the /omf ml switch and the two seg. reg. setup lines and its actually there.... woooooooow... i may well hook it to the registry and view at every startup now after all that.

Huge thanks to everyone who took the time to reply (and yes, i was targeting exe rather than com), i'm sure i'd have been wading through info for hours if it hadnt been pointed out - especially with the two lines.

Thank yooooooooou! ...phew, almost makes things like VB seem worthwhile...