Why doesn't the program display the string using int 20h?

Started by leetow2003, December 10, 2010, 05:23:06 AM

Previous topic - Next topic

leetow2003

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?

jj2007

Why should it? Which manual says there is a function associated with Int 20h?

See here for a valid manual.

dedndave

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 ?

japheth

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.

Magnum

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
Have a great day,
                         Andy

leetow2003

First I run command cmd under xp,and then run this program.Does it run in pure dos? 

Magnum

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.

Have a great day,
                         Andy

dedndave

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