装配x86处理器中的OFFSET运算符 [英] OFFSET operator in assembly x86 processors

查看:121
本文介绍了装配x86处理器中的OFFSET运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我对偏移操作员的概念感到困惑



这是一个示例来自我的教科书(假设bVal位于偏移00404000):



。数据

bVal字节?



。代码

mov esi,OFFSET bVal; ESI = 00404000



从我的例子中我理解的是,OFFSET只返回任何变量的地址,例如bVal。



到目前为止这是可以的,但是下一个例子显示OFFSET做了别的事情,这让人感到困惑。



示例:



.data

byteVal BYTE 10h



.code

mov esi,OFFSET byteVal

mov al,[esi]; AL = 10h



为什么al = 10h?根据前面的例子,不应该AL包含bVal的地址吗?



另外,如何将esi移动到al,这是一个较小的尺寸比esi?



我尝试了什么:



我有试图理解教科书的内容,但是这些例子显示了相互矛盾的信息。

Hi,

I am confused about the concept of the Offset Operator

Here is an example from my textbook (suppose bVal was located at offset 00404000):

.data
bVal Byte ?

.code
mov esi, OFFSET bVal ; ESI = 00404000

From what I understand from this example is that OFFSET simply returns the address of any variable, such as bVal.

This is ok so far, but the next example shows that OFFSET does something else, which is confusing.

Example:

.data
byteVal BYTE 10h

.code
mov esi, OFFSET byteVal
mov al, [esi] ; AL = 10h

Why is al = 10h? shouldn't AL contain the address of bVal, according to the previous example?

Also, how is it possible that esi can be moved to al, which is a smaller size than esi?

What I have tried:

I have tried to understand what the textbook is saying but the examples show contradicting information.

推荐答案

区别在于直接使用值还是从内存地址使用。



mov esi,OFFSET byteVal

这里byteVal的地址将被放入寄存器esi(假设为示例中的00404000)



mov al,[esi] ; AL = 10h

这里esi放在括号之间,如[esi],意思是不直接使用该值(值为00404000),但将其用作地址并将该内存中的字节加载到注册AL。



因此使用括号更改含义。一个更简单的例子是:

假设在内存中的地址1上存储了值5。

也可以说AL为0(例如使用XOR AL,AL)

当你执行时:

ADD AL ,1 ; AL为1(0 + 1 = 1)



但是,让AL再次清0,现在做:

ADD AL,[1] ; AL现在是5.而不是直接使用值1,它使用来自内存地址1的值,即5。



希望这会使它更加清晰。



祝你好运!
The difference is between using the value directly or from memory address.

mov esi, OFFSET byteVal
Here the address of byteVal will be put into register esi (assume 00404000 as in the example)

mov al, [esi] ; AL = 10h
Here the esi is put between brackets, like [esi], meaning not to use the value directly (value is 00404000) but use it as an address and load the byte from that memory into register AL.

So the meaning changes using the brackets. An easier example would be:
Lets say that on address 1 in memory there is a value 5 stored.
Lets also say that AL is 0 (using for example XOR AL, AL)
When you would execute:
ADD AL, 1; AL would be 1 (0 + 1 = 1)

But, lets clear AL to 0 again and now do:
ADD AL, [1]; AL would now be 5. Instead of using value 1 directly it uses the value from memory address 1, which is 5.

Hopefully this will make it somewhat more clear.

Good luck!


这篇关于装配x86处理器中的OFFSET运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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