When I assemble and link(16) the following code below, the output has some strange junk characters before the main string. I am assembling under Windows 7 with the commands:
ml /AT /c hello.asm
link16 hello.asm
.model tiny
.code
ORG 100H
HOST:
mov ah,9
mov dx,OFFSET HI
int 21H
mov ax,4C00H
int 21H
HI DB "Hello hello hello!$"
END HOST
Output, after 3 new lines, is: 3Ê┤ ║♫☺═!© L═!Hello hello hello!
Many thanks!
Interrupt 21h Function 9 expects the string to be at DS:DX. When you linked without /TINY the linker produced a 16-bit EXE file, and when the loader loads a 16-bit EXE it leaves the DS and ES segment registers set to the segment address of the PSP. For a 16-bit EXE the PSP segment precedes the program segment in memory, so the function started displaying at the offset address of the string, as calculated from the start of the program, but in the PSP segment, and displayed everything between the starting point and the '$' terminator.
If you had linked it with /TINY the linker would have produced a .COM file and the loader would have set all of the segment registers to the segment address of the PSP. And since for a .COM file the PSP is effectively part of the program, and you allowed room for it in the program address space with the ORG 100H, DS:DX would have pointed to the start of the string, and it would have displayed as expected.
your code is ok, but i use the following "template" for tiny model programs
.MODEL Tiny
.386
OPTION CaseMap:None
;####################################################################################
.CODE
;************************************************************************************
ORG 100h
_main PROC NEAR
mov dx,offset s$string
mov ah,9
int 21h
mov ax,4C00h
int 21h
_main ENDP
;************************************************************************************
s$string db 'Hello hello hello!',0Dh,0Ah,24h
;####################################################################################
END _main
in addition to what Michael said about using the /TINY switch with Link16.exe,
i would also use the "/omf" switch with ML.exe
ml /omf /c hello.asm
link16 /TINY hello.asm,hello.com;
on most versions of MASM, /omf implies /c, and /omf is probably the default
but - the switch behaviour varies a little from version to version :P
in some cases, the switches are case-sensitive - i think /omf is one of those
Many thanks for the quick replies, guys, and the detailed info. :t
I have been using this forum a lot of late, and hope to use it more. Great community you got going on here. :eusa_dance: :eusa_clap: