Problems with GNU as Intel syntax

Programming, for all ages and all languages.
SimonZilch
Posts: 8
Joined: Thu Jan 22, 2009 12:19 am

Re: Problems with GNU as Intel syntax

Post by SimonZilch »

earlz wrote:
I'm not sure if it matters, but when I did gas with intel syntax in my OS, I did

Code: Select all

.intel_syntax noprefix
I'm not sure of the difference though
"prefix" means you want to use percent signs('%') before your registers. "noprefix" means you don't. From what I've been able to determine, that's the only difference, and it has nothing to do with dollar signs('$'). Most Intel syntax assemblers (that I've used) don't prefix the registers with anything, but I like the idea of having a prefix to distinguish registers from labels. Unfortunately though, after years of using other assemblers, I'm too accustomed to NOT typing the prefix; so I've just given up trying and dropped the prefix.

Just to remind people of my remaining question:
SimonZilch wrote:The second problem I ran into is a warning for this code:
. . .

Code: Select all

	mov dword ptr [0xb8000], %eax
The warning is: "Warning: Treating `dword ptr [0xb8000]' as memory reference"
That doesn't make sense. Of course it's treating it as a memory reference. I very explicitly told it that it's a memory reference. . . .
So how do I get rid of this warning? Is my syntax wrong? If so, how do I do it right?
I've also determined that this gives the same warning:

Code: Select all

	.set VIDEO_MEM, 0xb8000 # same result with .eqv or .equiv instead of .set
	mov dword ptr [VIDEO_MEM], eax
as says: " Warning: Treating `dword ptr [VIDEO_MEM]' as memory reference"
Any thoughts?
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Problems with GNU as Intel syntax

Post by earlz »

This is strange. With my GCC it doesn't give any warnings on your code(with -Wall)

My test file is

Code: Select all

#include <stdlib.h>
#include <stdio.h>

int a;

int main(){

	__asm(".intel_syntax noprefix\n"
		"mov dword ptr [0xb8000], eax\n"
		".att_syntax\n");


	return 0;

}
are your trying to do inline code or standalone assembly files?

Code: Select all

[earlz@EarlzBeta-~] $ gcc --version
gcc (GCC) 3.3.5 (propolice)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[earlz@EarlzBeta-~] $ as --version
GNU assembler 2.15
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
This assembler was configured for a target of `i386-unknown-openbsd4.4'.
SimonZilch
Posts: 8
Joined: Thu Jan 22, 2009 12:19 am

Re: Problems with GNU as Intel syntax

Post by SimonZilch »

earlz wrote:This is strange. With my GCC it doesn't give any warnings on your code(with -Wall)
. . .
are your trying to do inline code or standalone assembly files?
. . .
I was doing plain standalone assembly, but it doesn't make any difference:

Code: Select all

simon@zilch1:~$ cat test.c 
int main()
{
        __asm(".intel_syntax noprefix\n"
        "mov dword ptr [0xb8000], eax\n"
        ".att_syntax\n");

        return 0;
}
simon@zilch1:~$ gcc -m32 -Xassembler --32 -c test.c 
/tmp/ccukgSfh.s: Assembler messages:
/tmp/ccukgSfh.s:13: Warning: Treating `dword ptr [0xb8000]' as memory reference
Note that "-m32" and "-Xassembler --32" tell the compiler and assembler (respectively) that I want 32-bit code (since I'm on a 64-bit system). It does the same thing with "-m64 -Xassembler --64".
My assembler version is a little more recent than yours by a few years:

Code: Select all

simon@zilch1:~$ as --version
GNU assembler version 2.17.50.0.18-1 20070731
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-redhat-linux'.
I guess the warning must have been added to the assembler after your version. I doubt it's anything with the compiler, but my gcc version's a little more recent too.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Problems with GNU as Intel syntax

Post by earlz »

hmm.. gcc and as must be getting a little rusty with its old age and code bloat lol
cygx
Posts: 2
Joined: Sat Feb 14, 2009 9:10 am

Re: Problems with GNU as Intel syntax

Post by cygx »

There is even more strangeness afoot. Consider the following code:

Code: Select all

void test(void)
{
    __asm__("movl %eax,($0xdeadbeaf)");
    __asm__("movl %eax,(%ecx)");

    __asm__(".intel_syntax prefix");

    __asm__("mov [dword ptr $0xdeadbeaf],%eax");
    __asm__("mov [dword ptr %ecx],%eax");

    __asm__(".intel_syntax noprefix");

    __asm__("mov [dword ptr 0xdeadbeaf],eax");
    __asm__("mov [dword ptr ecx],eax");

    __asm__(".att_syntax prefix");
}
When you look at the objdump, you'll find this

Code: Select all

   3:   a3 00 00 00 00          mov    %eax,0x0
   8:   89 01                   mov    %eax,(%ecx)
   a:   a3 00 00 00 00          mov    %eax,0x0
   f:   89 01                   mov    %eax,(%ecx)
  11:   a3 af be ad de          mov    %eax,0xdeadbeaf
  16:   89 01                   mov    %eax,(%ecx)
Only the line which generates the warning won't silently drop the value!?

----

Now, look at this code

Code: Select all

void test(void)
{
    *(int *)0xdeadbeaf = 0x1234;

    __asm__(".att_syntax prefix");
    __asm__("movl $0x1234,($0xdeadbeaf)");

    /* this won't compile: Error: too many memory references for 'mov'
    __asm__(".intel_syntax prefix");
    __asm__("mov [dword ptr $0xdeadbeaf],$0x1234");
    */

    __asm__(".intel_syntax noprefix");
    __asm__("mov [dword ptr 0xdeadbeaf],0x1234");

    __asm__(".att_syntax prefix");
}
and its objdump

Code: Select all

   3:   c7 05 af be ad de 34    movl   $0x1234,0xdeadbeaf
   a:   12 00 00
   d:   c7 05 00 00 00 00 34    movl   $0x1234,0x0
  14:   12 00 00
  17:   c7 05 af be ad de 34    movl   $0x1234,0xdeadbeaf
  1e:   12 00 00
Anyone here who can explain this?
cygx
Posts: 2
Joined: Sat Feb 14, 2009 9:10 am

Re: Problems with GNU as Intel syntax

Post by cygx »

Anyone here who can explain this?
I actually figured this out myself with help from the nice people at stackoverflow.

Here it the aswer as to How to use address constants in GCC x86 inline assembly.
Post Reply