繁体   English   中英

组装数组声明时“无此类指令错误”:

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

我有以下一段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的结果是特定于目标CPU的-另一种选择是.hword

7.60 .hword 表达式

这期望零个或多个表达式,并为每个表达式发出16位数字

该伪指令是.short的同义词; 根据目标体系结构,它也可能是.word的同义词。

顺便说一句:您说# define an array of 3 dwords在您的注释中# define an array of 3 dwords -但请注意DWDefine Word一个16位字的定义字。 NASM ,您将DD用于32位字。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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