Search code examples
x86gnu-assemblerattintel-syntax

X86 intel syntax - ambigious size for mov, junk h after expression?


I was working with AT&T syntax but thought i'd try out intel. I have this code:

.text
        .global _start

_start: 
        mov ebx, 0
        mov eax, 1          
        int 80h

Which should return 0, right? It did with AT&T before i converted it.

I'm assembling using:

 as out.s -msyntax=intel --32 -o out.o

But I get:

out.s:5: Error: ambiguous operand size for `mov'
out.s:6: Error: ambiguous operand size for `mov'
out.s:7: Error: junk `h' after expression

Where am I going wrong here?


Solution

  • Non ancient versions of GNU's Assembler provide support for Intel syntax, but there are some issues. -msyntax=intel isn't enough if you are looking for something closer to NASM/MASM's intel syntax. -msyntax=intel will switch the order of the operands so the destination is the first operand and the source operand are after. However you still need to prefix all the register names with % percent. So you'd likely find this would have worked:

        mov %ebx, 0
        mov %eax, 1  
    

    That would likely fix the errors on the MOV instructions. This is probably not what you want. To use Intel syntax without the % prefixes you can add this to the top of each of your assembly files:

    .intel_syntax noprefix
    

    By specifying this at the top of each of your assembly files you no longer need to assemble with the option -msyntax=intel.

    The junk 'h' after expression error is because GNU's assembler (even in Intel syntax mode) doesn't support constants with the base specified as a suffix. In your case 80h isn't recognized. GNU assembler requires base to specified by a prefix like 0x for hexadecimal. So to eliminate this error use:

        int 0x80
    

    Fixing these issues should allow this code to assemble.