The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: jmccaffrey on January 25, 2006, 07:22:29 PM

Title: IO using INT 21h?
Post by: jmccaffrey on January 25, 2006, 07:22:29 PM
Is it possible to perform console IO using Int 21h under Windows XP?  I'm a MASM32 newbie.  I've successfully assembled and linked the "Hello World" example which looks something like:

; some code up here . . . .

start:                          ; The CODE entry point to the program

    print chr$("Hey ho, this actually works.",13,10)
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start                       ; Tell MASM where the program ends

From snooping around, it looks like the IO is being performed by a call to a Windows API function.  That's cool but is it possible to perform console IO under Windows XP using an Int 21h along the lines of:

.data

msg db 'Hello World', '$'

.code

mov ah, 09h
lea dx, msg
int 21h

When I add this code to the working program above, when I attempt to execuite the resulting .exe, the program throws a fatal error.  Can you show me a working program that prints a message using Int 21h?  Thanks!

JM



Title: Re: IO using INT 21h?
Post by: MichaelW on January 25, 2006, 07:54:36 PM
Hello JM, welcome to the forum.

You can use the Interrupt 21h functions from a DOS program running under Windows, but not from a Windows program.


Title: Re: IO using INT 21h?
Post by: IAO on January 26, 2006, 12:20:38 PM
Hi to all:
My english is poor. But try.

Quote from: jmccaffrey on January 25, 2006, 07:22:29 PM
  Can you show me a working program that prints a message using Int 21h?  Thanks!

If you use the RADASM IDE, looks inside the directory: Radasm\Masm\Projects\Dos\LnkStub
There you have 3 examples.
Open readme.txt, and open lnkstub.asm, read these files.

Escuseme the errors

www.radasm.com

By(t)e ('_')
Title: Re: IO using INT 21h?
Post by: BytePtr on January 29, 2006, 01:00:41 PM
Quote from: jmccaffrey on January 25, 2006, 07:22:29 PM
Is it possible to perform console IO using Int 21h under Windows XP?

Tell me why you think that its not possible?
You can even code FIRE effect in asm (16 bit exe) and it works fine in XP.
This example needs atleast TASM 3.x becauze older versions does not understand stuff like: .startup and .exit. MASM should compile fine.

.model small
.stack 200h
.data
  txt db "Hey ho, this actually works.$"
.code
.startup
  lea dx, txt ; point DX to txt
  mov ah,9
  int 21h

  xor ah,ah  ; wait for keypress
  int 16h
.exit  ; give control back to DOS
end

Title: Re: IO using INT 21h?
Post by: jmccaffrey on January 30, 2006, 05:50:48 AM
I solved the problem after some experimentation.  It turns out, that as a couple people suggested, I was trying to assemble and link a 16-bit program on a 32-bit system (Windows XP).  I found a version 6 MASM/ML and an old 16-bit linker (I forget the version number but I think it is circa 1992).  I'm not on the machine I used (so I can't give the exact commands) but, after I found the right combination of command line swithes for ml.exe and link.exe, I could create both 16-bit .com and .exe files that ran fine on Windows XP.