Reputation: 33
I am good with M68000 but X86 is diffficult for me. I am trying to assemble this simple program with MASM
.MODEL SMALL
.data?
ONE dB ?
TWO dB ?
stack db 100 dup(?)
.data
MSG db 13,10, 'Enter deree of polynomials: $'
MSG2 db 13,10, 'Enter coefficient of x^ $'
MSG3 db 13,10, 'The polynomial created is: $'
MSG4 db 13,10, 'The first derivative is: $'
STR1 db 255 DUP('$')
.code
_start:
mov ax, offset MSG
mov ds, ax
end _start
and I keep getting the error Unknown relocation type (1) for symbol MSG. I know what this is (it happens when the displacement is bigger than that allowed by the model or something like this) but I do not know how to solve this error (I know MASM is a 32 bit assembler and I am trying to write a 16 bit code). What I am trying to do is to load the pointer to .data into ds register.
My makeit.bat
generated by the MASM32 IDE is:
@echo off
if exist "derivative 1.obj" del "derivative 1.obj"
if exist "derivative 1.exe" del "derivative 1.exe"
\masm32\bin\ml /c /coff "derivative 1.asm"
if errorlevel 1 goto errasm
\masm32\bin\PoLink /SUBSYSTEM:CONSOLE "derivative 1.obj"
if errorlevel 1 goto errlink dir "derivative 1.*" goto TheEnd
:errlink
echo _
echo Link error
goto TheEnd
:errasm
echo _
echo Assembly Error
goto TheEnd
:TheEnd
pause
Upvotes: 3
Views: 322
Reputation: 33
To all that gave me answers to the simple question above I am saying Thank you. Indeed the answer to my question is that the link16.exe is necessary to generate the 16 bit code. Another way I could assemble simply and fast my code was using WinAsm wich is an older IDE that I found by googling.
Upvotes: 0
Reputation: 47573
The MASM32 package doesn't come with support for 16-bit executable generation, although it's not difficult to alter this behaviour. The MASM assembler in the MASM32 package will generate 16-bit code but the linkers supplied will not generate 16-bit executables. This results in the type of error(s) you are seeing.
You can download a copy of an older linker that supports 16-bit targets. I've made link16.exe (version 5.60.339 Dec 5 1994) available for download on my server.
Place link16.exe
into the \masm32\bin
directory. You will have to modify the generated makeit.bat
file. The line that calls the linker (like link.exe
or polink.exe
) has to be replaced with:
\masm32\bin\link16.exe "filename.obj" ;
filename.obj
is the name of the file you want to link. Change it to suit your project. The semicolon on the end will default all the file names and won't prompt for them. You will then have to modify the the ml
line in makeit.bat
so that it doesn't produce coff
files. To do that remove /coff
option:
\masm32\bin\ml /c "filename.asm"
Again filename.asm
can be replaced by the name of the file in your project.
Once you are able to generate a 16-bit executable some issues with your code:
Remove stack db 100 dup(?)
and use the .stack
directive instead
.stack 100h
You need to set up the segment value of MSG
in DS instead:
mov ax, seg MSG mov ds, ax
With the .small
model there is only one data
segment. In the .small
model .data
and .data?
will be combined into a single .data
segment. With this memory model you can also initialize DS this way:
mov ax, @data mov ds, ax
For an DOS EXE program you'll need to exit with something like the DOS exit interrupt
mov ax, 4c00h int 21h
If you are using MASM32 on a 64-bit version of Windows you wil not be able to directly run the 16-bit applications you create. You will have to download an emulator like DOSBox to run it, or install Virtual Machine (VMWare, VirtualBox, QEMU etc) software with a version of DOS/Windows that can run the code.
Upvotes: 5
Reputation: 28828
For 16 bit assembly, with dot directives (like .model, .data, .code) the syntax is:
mov ax, @data
mov ds, ax
Upvotes: 0