本文介绍了将恒定字节值移至%ebx时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究《计算机系统》,《程序员的视角》 (第3版),《实践问题3.3》包含以下内容:

I'm working through Computer Systems, A Programmer's Perspective (3rd edition), and Practice Problem 3.3 contains the following line:

movb $0xF, (%ebx)

我应该找出这行x86-64汇编出了什么问题,答案键指出:不能将%ebx用作地址寄存器,这对我来说没有意义。我的理解是,该行打算将0xF复制到主内存中的某个位置,但是%ebx是32位寄存器,在64位计算机上内存地址为64位宽,因此%ebx无法保存内存地址,因此它不能被取消引用(取消引用是%ebx周围的括号表示的,对吗?)。但是,回头看书中的几页(如果有的话,请参阅第183页),有一个示例详细说明了五个mov操作数-目标组合,其中之一是:

I'm supposed to find out what's wrong with this line of x86-64 assembly, and the answer key states: "Cannot use %ebx as address register", which doesn't make sense to me. My understanding is that this line intends to copy 0xF to a location in main memory, however %ebx is a 32-bit register, memory addresses are 64 bits wide on 64-bit machines, and so %ebx cannot hold a memory address, therefore it cannot be dereferenced (dereferencing is what the parentheses around %ebx represent, correct?). However, looking a few pages back in the book (page 183, if you have it) there is an example detailing the five mov operand--destination combinations, one of which is:

movb $-17, (%esp)         Immediate--Memory, 1 byte

%esp是32位寄存器,就像%ebx一样!此示例显示了将字节值移至已取消引用的32位寄存器!这对我来说没有任何意义,因为%esp如何包含64位地址?我会完全误解汇编吗?

%esp is a 32-bit register just like %ebx! And this example shows a byte value being moved to a dereferenced 32-bit register! Which doesn't make sense to me, because how can %esp contain a 64-bit address? Do I completely misunderstand assembly?

推荐答案

您是对的,

movb $-17, (%esp)         Immediate--Memory, 1 byte

不应被允许。实际上,作者将其发布为错字。
查看他们的(Ctrl-F表示 p 。183)。

should not be allowed. In fact the authors have posted this as a typo.Check out their errata list (Ctrl-F for "p. 183").

这篇关于将恒定字节值移至%ebx时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 20:09