cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/02/22:16:15

From: Simon Schubert <ba122504 AT aic-online DOT baynet DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q] using int 0x21 to print text with inline asm
Date: Sat, 30 Aug 1997 18:19:19 +0200
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
Lines: 97
Distribution: world
Message-ID: <34084807.7116B438@aic-online.baynet.de>
References: <199708261830 DOT LAA11093 AT adit DOT ap DOT net>
Reply-To: ba122504 AT aic-online DOT baynet DOT de
NNTP-Posting-Host: dial032.augsburg.baynet.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nate Eldredge wrote:
> 
> At 11:35  8/25/1997 GMT, firewind wrote:
> >Egg brains <eggbrains AT aol DOT com> wrote:
> >> char *myHappy;      /* i have also tried using a character */
> >  ^^^^^^^^^^^^^^ (1)
> >> void main()
> >  ^^^^^^^^^^^ (2)
> >> {
> >
> >> myHappy = "Hello, world!";
> >  ^^^^^^^^^^^^^^^^^^^^^^^^^^ (3)
> >> asm("movw _myHappy, %dx");
> >> asm("movb $9, %ah");
> >> asm("int $0x21");
> >> }

> All this dodges the real problem, which is that your program runs in
> protected mode, and the address of the string is a 32-bit pointer relative
> to the program's DS. The DOS INT 21h function expects a real-mode address,
> with 16-bit segment and offset. You are giving it the protected-mode DS
> selector, and what seems to be either the low or high half of the string's
> 32-bit address. The contents of this address in conventional memory are
> god-knows-what.

That's wrong. What for is - if you were right - the dos-extender?
the dos-extender converts the interrupt calls from protected mode to the
right 
parameters and then calls the real mode int. So you just have to move
the *whole*
offset of myHappy into dx, which must be in protected mode edx, a 32 bit
offset.

> Another problem is that INT 21h function 9 wants a `$'-terminated string (a
> holdover from CPM days). You should be initializing myHappy to "Hello, world!$".
right.

> Furthermore, the asm instruction "int $0x21" generates an INT 21h in
> *protected mode*. If it's handled there, it will never get to real mode and
> DOS. 
it's handled there by the dos-extender and correcty (with the right
register values)
reflected to dos.

> This is obviously not your problem currently, and is probably unlikely
> to occur, but it's a bad idea all the same.
that was the whole problem, having not the right offset, the
dos-extender couldn't
process the int correctly.

> So. If you really want to use DOS function 9 to print a string:
> - `$'-terminate it.

> - Move it to somewhere in conventional memory, either the transfer buffer or
> a chunk you've allocated with __dpmi_allocate_dos_memory.
nonono. all that does the dos-extender.

> - Use __dpmi_int to call INT 21, and be sure to use the address of the
> conventional memory copy of the string.
just pass the 32 bit offset and call the int.

by the way... why do you use this shitty "asm ()"? you can also use the 
better (and more compatible) "intdos ()" or "int86 ()"!

Bye
Simon

------------------------ snip -----------------------
char *myHappy;

int main ()
{       
        myHappy = "Hello, world!$";
        asm ("movl  _myHappy, %edx");
        asm ("movb $9, %ah");
        asm ("int $0x21");
        return 0;
}

----------------- double snip ---------------------
#include <dos.h>

char *myHappy;

int main ()
{       
        union REGS r;

        myHappy = "Hello, world!$";
        r.d.edx = (int)myHappy;
        r.h.ah = 9;
        intdos (&r, &r);
        return 0;
}

----------------- end snip --------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019