在32位汇编代码中使用movw时,mov的指令后缀无效 [英] Invalid instruction suffix for mov when using movw in 32-bit Assembly code

查看:379
本文介绍了在32位汇编代码中使用movw时,mov的指令后缀无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译我的汇编文件时(下面的代码),我收到错误消息:指向'mov'的无效指令后缀指向我的movw指令行.现在,我已经在Google上搜索了一下,但仍然不明白这一点.我的CPU是64位,但是由于我明确告诉gcc生成32位代码,所以movw不应不是移动寄存器低16位的有效指令吗?我正在从我的书中几乎逐字复制该示例.

When I compile my assembly file (code below) I get the message Error: invalid instruction suffix for `mov' pointing to my movw instruction line. Now, I've Googled a bit and still don't understand this. My CPU is 64-bit, but since I'm clearly telling gcc to generate 32-bit code shouldn't movw be a valid instruction to move the lower 16 bits of a register? I'm copying the example almost verbatim from my book at hand.

remnux @ remnux:〜/Assembly $ gcc -o zx zx.s -gstabs -m32 zx.s:汇编程序消息: zx.s:10:错误:"mov"

remnux@remnux:~/Assembly$ gcc -o zx zx.s -gstabs -m32 zx.s: Assembler messages: zx.s:10: Error: invalid instruction suffix for `mov'

.code32
.section .data
myString:
  .asciz "eax is now %d\n"
.section .text
.globl main
main:
  movl $9999, %ebx
  movl $3, %eax
  movw %ax, %ebx
  pushl %ebx
  pushl %eax
  pushl %ebx
  pushl $myString
  call printf
  add $8, %esp
  popl %eax
  popl %ebx
  movzx %ax, %ebx
  pushl %ebx
  pushl %eax
  pushl %ebx
  pushl $myString
  call printf
  add $8, %esp
  call printf
  call exit

推荐答案

克里斯·多德(Chris Dodd)是正确的,但发表了评论而不是答案.由于每个答案都应以结尾结尾,因此我在回答自己的问题.

Chris Dodd was right but posted a comment and not an answer. As each answer should have closure, I'm answering my own question.

我正在使用带有32位%ebx的16位movw,这本书中的示例不正确. movw将与%bx等16位寄存器一起使用,或者movl将32位移入%ebx.

I was using a 16-bit movw with a 32-bit %ebx and the example in the book was incorrect. movw will work with a 16-bit register such as %bx, or movl to move 32 bits into %ebx.

这篇关于在32位汇编代码中使用movw时,mov的指令后缀无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆