www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/21/19:46:33

From: speed AT connext DOT net
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ASM in DJGPP V2
Date: Sat, 21 Dec 1996 23:14:15 GMT
Message-ID: <32bc6a94.63674170@news.connext.net>
References: <2615 DOT 850942893 AT cs DOT ucl DOT ac DOT uk>
Lines: 92
NNTP-Posting-Host: connext.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Let's see what I can offer here...

1) You don't need to use the register loading for constants.  So,
this:
>			mov ax,16;
>			mov dx,16;

becomes:
                              "movw $0x16d, %%ax\n\t"
                              "movw $0x16d, %%dx\n\t"

Note that constants in AT&T assembly default to hex, so you need to
postfix them with a 'd' for decimal.  Constants are always prefixed
with a '$'.

2) Use local labels for your jumps.  This is a WaitRetrace
pseudofunction I wrote - not related to what you are doing, but a good
example for jumps within inline asm, as well as constants:

#define WaitRetrace() \
__asm__ __volatile__ ( \
    "movw $0x3da, %%dx\n\t" \
  "0:\n\t" \
    "inb %%dx, %%al\n\t" \
    "testb $0x08, %%al\n\t" \
    "jnz 0b\n\t" \
  "1:\n\t" \
    "inb %%dx, %%al\n\t" \
    "testb $0x08, %%al\n\t" \
    "jz 1b" \
    : : : "%eax", "%edx")

the 0: and 1: are labels.  The references to them are 'jnz 0b' and 'jz
1b'.  The 'b' means it is a backwards reference.  Use 'f' for forward
references.  As far as I know, the labels must be numeric.

3) The "cc" you asked about refers to the condition codes in the flags
register.  So if you, for example, change the status of the zero flag,
you'll want "cc" in your clobber list.  I'm not sure what the "rm"
refers to - anyone?

4) The references to es and ds are going to give you problems in
protected mode.  I think you'll need to use _dos_ds() but I'm not sure
on the details.  Perhaps someone else can help out with this part?

Best of Luck.

- Mark

P.S.  I usually don't quote large blocks, but in this case I will in
case someone did not get the original post (and also because I did not
completely solve the problem)...

On Wed, 18 Dec 1996 21:01:33 GMT, Chris AUSTIN <C DOT Austin AT cs DOT ucl DOT ac DOT uk>
wrote:

[working Intel version]:

>                for (int row=0; row<16; row++)
>                    memcpy(&s.data[(y+row)*s.width+x],&data[row*16],16);
>		unsigned char* b=s.data+y*s.width+x;
>		const unsigned char* p=data;
>		int scrw=s.width;
>
>		asm{
>			push ds;
>			mov ax,16;
>			mov dx,16;
>			mov bx,scrw;
>			sub bx,ax;
>			les di,b;
>			lds si,p;
>			cld;
>			shr ax,1;
>		}
>		rowloop:
>		asm{
>			mov cx,ax;
>			rep movsw;
>			add di,bx;
>			dec dx;
>			jnz rowloop;
>			pop ds;
>		}
>

[the attempted conversion]:

>		register unsigned long b asm ("%edi") = s.data+y*s.width+x;
>		register unsigned short offset asm ("%ebx") = s.width-16;
>                register unsigned long d asm ("%esi") = &data[0];
>
>		asm volatile (" cld                \n"
>                              " push %%es          \n"
>                              " movw %w0,%%es      \n"
>                              "rowloop:            \n"
>                              " movl %%eax,%%ecx   \n"
>                              " rep; movsb         \n"
>                              " addl %%ebx,%%edi   \n"
>                              " decl %%edx         \n"
>                              " jnz rowloop        \n"
>                              " pop %%es             "
>                              :
>                              : "rm" (_my_ds()), "a" (16), "d" (16),
>                                "b" (offset), "S" (d), "D" (b)
>                              : "%eax", "%ebx", "%ecx", "%edx",
>                                "%esi", "%edi", "cc");

- Raw text -


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