www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/27/14:47:11

Date: Tue, 27 Oct 1998 19:47:00 +0000 (GMT)
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: Converting Intel asm to AT&T syntax
In-Reply-To: <713cu6$msm$1@supernews.com>
Message-ID: <Pine.OSF.4.05.9810271928280.22379-100000@sable.ox.ac.uk>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Mon, 26 Oct 1998, Thiessen wrote:

> Hi,
> First of all, I hope this isn't the wrong newsgroup to post this in.
> I am trying to learn the AT&T syntax of inline assembly.

For these functions you don't need it, here are versions that
don't use inline assembly (explicitly):

/*get_mode*/
unsigned char get_mode(void)
{
    __dpmi_regs r;
    r.x.ax = 0x0f00;
    __dpmi_int (0x10, &r);
    return r.x.ax & 0xff;
}
/*save_mode*/
void set_mode(unsigned char mode)
{
    __dpmi_regs r;
    r.x.ax = mode;
    __dpmi_int (0x10, &r);
}
/*pset*/
void pset(int x,int y,unsigned char color)
{
    __dpmi_regs r;
    r.x.ax = 0x0c00 + color;
    r.x.cx = x;
    r.x.dx = y;
    __dpmi_int (0x10, &r);
}
/*line*/
void line(int x1,int y1,int x2,int y2,unsigned char color)
{
    int x,y;
    for(y=y1;y<=y2;y++)
        pset(x1,y,color);
}

Since you said you were learning the AT&T syntax, here are the
first three functions translated *literally* into AT&T syntax.  
These might not work in DPMI; I have no idea.  I also can't test
them at the moment; I'm sorry.

/*get_mode*/
unsigned char get_mode(void)
{
    unsigned char mode;
    asm volatile (
        "movb $0x0f, %%ah \n\t"
        "int $0x10        \n\t"
        "movb %%al, %0    \n\t"
    : /* outputs */
        "=m" (mode)   /* Output to `mode' as %0, in a memory location */
    : /* inputs (none) */
    : /* clobbered registers */
        "eax"         /* maybe others are clobbered too? */
    );
    return(mode);
}
/*save_mode*/
void set_mode(unsigned char mode)
{
    asm volatile (
        "movb $0, %%ah   \n\t"
        "movb %0, %%al   \n\t"
        "int $0x10      \n\t"
    : /* outputs (none) */
    : /* inputs */
        "m" (mode)    /* Use `mode' as %0, from memory */
    : /* clobbered registers */
        "eax"         /* maybe others? */
    );
}
/*pset*/
void pset(int x,int y,unsigned char color)
{
    asm volatile (
        "movb $0x0c, %%ah   \n\t"
        "movb %0, %%al      \n\t"
        "movw %1, %%cx      \n\t"
        "movw %2, %%dx      \n\t"
        "int $0x10         \n\t"
    : /* outputs (none) */
    : /* inputs */
        "m" (color),      /* %0 */
        "m" (x),          /* %1 */
        "m" (y)           /* %2 */
    : /* clobbered registers */
        "eax", "ecx", "edx"   /* and any others clobbered */
    );
}

These are actually very long winded versions; the functions can
be written more briefly by using the `inputs' sections to load
the registers, rather than doing it in out code itself.  But if
you want the optimal version, use the one that's all in C.

> I need to convert
> some inline assembly functions to the AT&T syntax because DJGPP doesn't
> support the way I have it below.  I can't figure it out
> since I am unfamiliar with any kind of assembly language.
> The code is below.  If anyone could help convert it so I would know what to
> do for future programs that use inline assembly,or if anyone could reccomend
> a link to a site that can explain what I am trying to learn I would
> appreciate it.

See Brennan's Guide to Inline Assembler in djgpp:

    http://brennan.home.ml.org/djgpp/djgpp_asm.html

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

xu do tavla fo la lojban  --  http://xiron.pc.helsinki.fi/lojban/lojban.html

- Raw text -


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