Author Topic: when i run the exe file generated by this code MS DOS is terminated.  (Read 3553 times)

Ehsanullah

  • Guest
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

  • Member
  • *****
  • Posts: 7557
  • Assembler is fun ;-)
    • MasmBasic
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #1 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)?

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #2 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.

Gunther
Get your facts first, and then you can distort them.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #3 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.
Well Microsoft, here’s another nice mess you’ve gotten us into.

jj2007

  • Member
  • *****
  • Posts: 7557
  • Assembler is fun ;-)
    • MasmBasic
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #4 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.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #5 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

Ehsanullah

  • Guest
Re: when i run the exe file generated by this code MS DOS is terminated.
« Reply #6 on: November 13, 2013, 04:18:16 AM »
Thank you all for being help full.