我有以下一段 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
但是当我编译这个时,我不断收到以下错误:
$ gcc my_asm.s
my_asm.s: Assembler messages:
my_asm.s:7: Error: no such instruction: `array_word DW 1,2,3'
这是我使用的 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.
最佳答案
您的语法错误 - gas
(由 gcc
为汇编文件调用)使用与 NASM
等其他汇编程序不同的语法。
使用
array_word: .word 1, 2, 3
另见 https://sourceware.org/binutils/docs/as/Word.html#Word
请注意,.word
的结果是特定于 objective-c PU 的 - 一个替代方案是 .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
.
顺便说一下:你在评论中说 #define an array of 3 dwords
- 但请注意 DW
是 Define Word
定义一个 16 位字。在 NASM
中,您将对 32 位字使用 DD
。
关于arrays - "no such instruction error"组装数组时声明:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34349675/