The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: Ehsanullah on November 10, 2013, 02:13:44 AM

Title: when i run the exe file generated by this code MS DOS is terminated.
Post by: Ehsanullah on November 10, 2013, 02:13:44 AM
I have typed this code in masm and assembled it when i run the exe file. MS DOS is terminated and a message box appears which says "The NTVDM has encounterd an illegal instruction. CS:0000 IP:0077 OP:f0 37 14 02 . "


.model small
.data
.code
.startup
mov ax,2
mov bx,3
mov ax,bx
int 21h
.exit
end


Please help me what is wrong with the code.
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: jj2007 on November 10, 2013, 02:36:20 AM
.model small
.386
.data

By the way: What is int 21 with ah=0? A variant to exit program (ah=4C)?
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: Gunther on November 10, 2013, 03:15:46 AM
Hi novice,

welcome to the forum. There's an interesting thread inside the 16 bit forum. There you can find working examples for your problem. (http://masm32.com/board/index.php?topic=2555.msg26812#msg26812)

Gunther
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: MichaelW on November 10, 2013, 07:57:18 AM
Interrupt 21h with AH=0 is the Terminate Program function intended for use by COM programs. After it completes all the other termination actions (basically, closing files, restoring the termination, CTRL+C handler, and Critical-Error handler addresses, and freeing memory) it transfers control to the termination address specified in the PSP. I did not test this, but I can guess that the direct problem is with the location of the PSP in memory. For a COM program the PSP is in the same segment as the program, but for an EXE program it is in a different segment.
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: jj2007 on November 10, 2013, 11:04:28 AM
Interrupt 21h with AH=0 is the Terminate Program function intended for use by COM programs.

Thanks, Michael. I grew up with GEMDOS, and vaguely remembered that:
PtermØ() terminates the application returning an exit code of 0 indicating no errors. (http://cd.textfiles.com/ataricompendium/BOOK/PDF/GEMDOS.PDF)
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: dedndave on November 10, 2013, 11:35:41 AM
yah - to use AH=0, the CS segment should point to the PSP
kinda hard in an EXE - lol - i guess you could do it, though
in the old days (really old days), they used to push the PSP and a 0 at the beginning of the EXE
then, do a RETF to terminate
that took you to PSP:0, where there is an INT 20h instruction

he has a .exit in there, so.....

i suspect what the OP is really after is a way to display the results of an ADD
which, the number needs to be converted to ASCII, then...
because it is a single digit, INT 21h, AH=2 could be used

Code: [Select]
mov ax,2
mov dx,3
add dx,ax
or dl,30h
mov ah,2
int 21h
Title: Re: when i run the exe file generated by this code MS DOS is terminated.
Post by: Ehsanullah on November 13, 2013, 04:18:16 AM
Thank you all for being help full.