The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: leetow2003 on December 10, 2010, 05:23:06 AM

Title: Why doesn't the program display the string using int 20h?
Post by: leetow2003 on December 10, 2010, 05:23:06 AM
Look:
data segment
  str1 db 'hello','$'
data ends
;
code   segment
       assume cs:code,ds:data
start:
       mov ax,data
       mov ds,ax
       lea dx,str1
       mov ah,09h
       int 21h

       mov ax,4c00h
       int 21h
       ;int 20h   --------------------The second  using this sentence
code   ends
       end start
This program can display the string "hello",but when I
use int 20h to exit instead of mov ax,4c00h and int 21h,
this program doesd't display any string,why?
Title: Re: Why doesn't the program display the string using int 20h?
Post by: jj2007 on December 10, 2010, 08:04:14 AM
Why should it? Which manual says there is a function associated with Int 20h?

See here (http://spike.scu.edu.au/~barry/interrupts.html) for a valid manual.
Title: Re: Why doesn't the program display the string using int 20h?
Post by: dedndave on December 10, 2010, 08:07:56 AM
INT 20h is the old Terminate Program - it requires no parameters   :bg

it works here, either way
i am using XP MCE2005 SP2 at the moment

what OS are you using ?
what commandlines are you using to build it ?
Title: Re: Why doesn't the program display the string using int 20h?
Post by: japheth on December 10, 2010, 08:18:40 AM
Quote from: leetow2003 on December 10, 2010, 05:23:06 AM
This program can display the string "hello",but when I
use int 20h to exit instead of mov ax,4c00h and int 21h,
this program doesd't display any string,why?

Int 20h is supposed to be used by .COM programs only.

Or, more exactly: the function expects CS to hold the current PSP on entry.
Title: Re: Why doesn't the program display the string using int 20h?
Post by: Magnum on December 10, 2010, 12:29:36 PM
Do you have Ralph's Interrupt List?

It has every Interrupt. (Even ones for Win 95)


.model       tiny
.386
.code

org          100h

begin:

jmp          start

; data goes here

out_string  db "H", 07h, "e",07h, "l", 07h,"l", 07h,"o", 07h," ", 07h,"W", 07h,"o", 07h,"r", 07h,"l", 07h,"d", 07h
number      db  $ - out_string

start:

   
    mov dx,0b800h
    mov es,dx
    mov cl, number
    mov si, OFFSET out_string
move:
    lodsw
    stosw
    loop move
   
    int     20h ; proper exit

end begin
Title: Re: Why doesn't the program display the string using int 20h?
Post by: leetow2003 on December 10, 2010, 12:58:12 PM
First I run command cmd under xp,and then run this program.Does it run in pure dos? 
Title: Re: Why doesn't the program display the string using int 20h?
Post by: Magnum on December 10, 2010, 01:29:39 PM
Quote from: leetow2003 on December 10, 2010, 12:58:12 PM
First I run command cmd under xp,and then run this program.Does it run in pure dos? 

Yes, this code was designed for use on all DOS versions.

You can even run it from a Boot Disk floppy if you have a floppy disk drive.

Title: Re: Why doesn't the program display the string using int 20h?
Post by: dedndave on December 10, 2010, 02:23:55 PM
that is because it is a .COM program
the CS register is the same as the PSP segment, unless you change it

this is not the case for .EXE programs
for .EXE programs, the PSP segment is passed to the program in DS and ES registers at startup
at the location PSP:0000, is an INT 20h instruction
so, for .EXE's, you can do this....
Start:  xor     ax,ax
        push    es
        push    ax
;
;rest of program here
;
        retf           ;terminate with FAR RET to PSP:0000

        END     Start


the "proper" way to generate a RETF is by declaring the main procedure as FAR...
_main   PROC    FAR

        xor     ax,ax
        push    es
        push    ax
;
;rest of program here
;
        ret           ;terminate with FAR RET to PSP:0000

_main   ENDP

        END     _main


this method also works for .COM programs, except you do not need to change the CS register prior to exit, so a NEAR RET may be used
also, with .COM programs, the 0000 is already pushed on the stack for you
_main   PROC    NEAR
;
;rest of program here
;
        ret           ;terminate with NEAR RET to PSP:0000

_main   ENDP

        END     _main