[英]“no such instruction error” when assembling an array declaration:
I have the following piece of x86 assembly code: 我有以下一段x86汇编代码:
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:
$ 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
. 您的语法是错误的
gas
(由gcc
调用的汇编文件)使用的语法与NASM
等其他汇编器的语法不同。
Use 采用
array_word: .word 1, 2, 3
See also https://sourceware.org/binutils/docs/as/Word.html#Word 另请参阅https://sourceware.org/binutils/docs/as/Word.html#Word
Note that the result of .word
is target CPU specific - an alternative is .hword
: 请注意,
.word
的结果是特定于目标CPU的-另一种选择是.hword
:
7.60 .hword expressions
7.60 .hword 表达式
This expects zero or more expressions, and emits a 16 bit number for each.
这期望零个或多个表达式,并为每个表达式发出16位数字 。
This directive is a synonym for
.short
;该伪指令是
.short
的同义词; depending on the target architecture, it may also be a synonym for.word
.根据目标体系结构,它也可能是
.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. 顺便说一句:您说
# define an array of 3 dwords
在您的注释中# define an array of 3 dwords
-但请注意DW
是Define Word
一个16位字的定义字。 In NASM
, you would use DD
for 32 bit words. 在
NASM
,您将DD
用于32位字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.