www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/01/11:13:31

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help with Inline Assembly in DJGPP
Date: Sat, 1 Feb 1997 14:02:02 +0000
Organization: None
Distribution: world
Message-ID: <uK3oVGAaz08yEw0a@talula.demon.co.uk>
References: <Pine DOT SV4 DOT 3 DOT 94 DOT 970131204350 DOT 10972D-100000 AT aludra DOT usc DOT edu>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 71
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

rellwood writes:
>Can someone please explain how convert Turbo C++ inline Assembly to
>DJGPP's format?  For example, one piece of my code looks something like
>this:
>
> __asm {
>        push ds
>        mov cx, DOUBLE_BUFFER_SIZE
>        les di, temp_video_buffer
>        mov ax, 320
>        mul zero
>        add di, ax
>        lds si, temp_double_buffer
>        rep movsw
>        pop ds
>   }
>
>(As you can guess from the variable names, this is *suppose to* copy data
>from a double buffer to the real video buffer.)

Converting real mode assembly code to the protected mode djgpp
environment is a non-trivial task. You are going to run up against
several issues:

- djgpp and Borland use a totally different asm syntax (IMHO the djgpp 
  one is vastly superior, but that doesn't help you much if you have   
  lots of code in the Borland format :-)

- your routine is written with 16 bit instructions, while djgpp runs in 
  32 bit mode. So 'rep movsw' doesn't use si and di with cx as the loop 
  counter, but esi, edi, and ecx. Get a book on 386 asm: it is
  significantly improved from the 8086 instructions used by Borland :-)

- your routine is written for real mode, and djgpp programs run in 
  protected mode. This totally changes the way you access video memory.

There are several documents around explaining how to use inline asm and
access video memory with djgpp, eg. http://www.rt66.com/~brennan/djgpp/.
But it's not a simple conversion process: be prepared to do some major
rewriting. The specific example you posted would convert to something
like (this is to copy a 320x200 image to a mode 13h screen):

  Easy solution:

    #include <sys/movedata.h>

    _dosmemputl(doublebuffer, 320*200/4, 0xA0000);


  In asm:

    #include <go32.h>

    asm (
      " pushw %%es ; "
      " movw %w0, %%es ; "
      " rep ; movsl ; "
      " popw %%es "
    :                           /* no outputs */

    : "r" (_dos_ds),            /* segment selector in any reg */
      "S" (doublebuffer),       /* line pointer in esi */
      "D" (0xA0000),            /* destination address in edi */
      "c" (320*200/4)           /* size in ecx */
    );


/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
 */

- Raw text -


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