News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

when i run the exe file generated by this code MS DOS is terminated.

Started by Ehsanullah, November 10, 2013, 02:13:44 AM

Previous topic - Next topic

Ehsanullah

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.

jj2007

.model small
.386
.data

By the way: What is int 21 with ah=0? A variant to exit program (ah=4C)?

Gunther

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.

Gunther
You have to know the facts before you can distort them.

MichaelW

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.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Quote from: 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.

Thanks, Michael. I grew up with GEMDOS, and vaguely remembered that:
PtermØ() terminates the application returning an exit code of 0 indicating no errors.

dedndave

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

mov ax,2
mov dx,3
add dx,ax
or dl,30h
mov ah,2
int 21h