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

1

7

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?

Highlander answered 14/10, 2017 at 15:23 Comment(5)
I thought the global directive in as is wo aRios
At the top of your file assembly file .intel_syntax noprefixErse
.section .text .globl _startRios
@Rios GNU assembler supports .globl and .globalErse
And you'll need to change int 80h to int 0x80 as GNU assembler doesn't support the suffixes like h. It uses prefixed notation to determine the base of a number 0x for hex.Erse
E
11

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.

Erse answered 14/10, 2017 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.