简体   繁体   中英

“no such instruction error” when assembling an array declaration:

I have the following piece of x86 assembly code:

 1
 2        .text
 3
 4        .data
 5
 6        # define an array of 3 dwords
 7        array_word DW 1, 2, 3
 8
 9
10        .globl main
11
12main:
13 # nothing interesting ..
14

But when I compile this, I keep getting the following error:

$ gcc my_asm.s 
my_asm.s: Assembler messages:
my_asm.s:7: Error: no such instruction: `array_word DW 1,2,3'

This is the gcc I use:

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
Copyright (C) 2010 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.

Your syntax is wrong - gas (which is invoked by gcc for assembly files) uses a different syntax than other assemblers like NASM .

Use

array_word: .word 1, 2, 3

See also https://sourceware.org/binutils/docs/as/Word.html#Word

Note that the result of .word is target CPU specific - an alternative is .hword :

7.60 .hword expressions

This expects zero or more expressions, and emits a 16 bit number for each.

This directive is a synonym for .short ; depending on the target architecture, it may also be a synonym for .word .

By the way: you say # define an array of 3 dwords in your comment - but note that DW is Define Word which defines a 16 bit word. In NASM , you would use DD for 32 bit words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM