arrays - "no such instruction error"组装数组时声明:

标签 arrays assembly x86 redhat

我有以下一段 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 - 但请注意 DWDefine Word 定义一个 16 位字。在 NASM 中,您将对 32 位字使用 DD

关于arrays - "no such instruction error"组装数组时声明:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34349675/

相关文章:

assembly - 有没有办法在 x86 上使用 MMX/SSE 减去压缩的无符号双字,饱和?

php - 我怎样才能用数据库中的数据制作这个数组?

c - 无法理解汇编逻辑

assembly - NASM 程序集 : Can't find valid values for all labels after 1004 passes

c - MIPS 中的错误寻址 - 矩阵乘法

将 C 变量的内容复制到寄存器 (GCC)

java - Java中递归地求数组中数字的总和

python - 如何有效地检查 numpy 数组包含给定范围内的项目?

javascript - php如何将数组添加到数组无限

assembly - 为什么这段 C 代码会生成这个汇编代码