用于x86处理器的汇编语言的OFFSET运算符 [英] OFFSET Operator in Assembly language for x86 Processors

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

问题描述

我对 OFFSET 运算符的概念感到相当困惑.根据Kip R. Irvine的《 x86处理器的汇编语言》一书,他将Offset运算符定义为返回变量到其封闭段开头的距离的运算符.他还说,偏移量运算符返回数据标签的偏移量,该偏移量表示标签到数据段开头的距离(以字节为单位).偏移量是多少?标签与数据段开头之间的距离是什么意思?另外,他是否得出了这个结果:

I am rather confused by the concept OFFSET Operator. According to Kip R. Irvine's book Assembly Language for x86 Processors, he defines the Offset Operator as the operator that returns the distance of a variable from the beginning of its enclosing segment. He also says the Offset Operator returns the offset of a data label and that represents the distance (in bytes) of the label from the beginning of the data segment. What is the offset? What does he mean by the distance of the label from the beginning of the data segment? Also, did he come about to this result:

他声明了三种不同类型的变量:

He declares three different types of variables:

.data
bVal  BYTE ?
wVal  WORD ?
dVal  DWORD ?
dVal2 DWORD ?

如果bVal位于偏移量00404000(十六进制)处,则OFFSET运算符将返回以下值:

If bVal were located at offset 00404000 (hexadecimal), the OFFSET operator would return the following values:

mov esi, OFFSET bVal     ;ESI = 00404000h
mov esi, OFFSET wVal     ;ESI = 00404001h
mov esi, OFFSET dVal     ;ESI = 00404003h
mov esi, OFFSET dVal2    ;ESI = 00404007h

这些价​​值从何而来?请帮忙.非常感谢!

Where did he arrive at those values? Please help. Thank you so much!

推荐答案

在16位代码之外,在正常的OS上,虚拟内存是平坦的,所有段的base = 0.

Outside of 16-bit code, on normal OSes, virtual memory is flat, with all the segments having base=0.

所以说 OFFSET var 为您提供 var 的地址作为立即数,而不是从地址中加载是一种复杂的方式.

So it's just a complicated way to say that OFFSET var gives you the address of var as an immediate, instead of loading from it.

mov esi, bVal          ; load from [bVal], in MASM syntax

mov esi, OFFSET bVal   ; esi= address of bVal
mov esi, [esi]         ; load from [bVal]

另请参见 [var]和var之间的组装差异了解MASM和NASM语法之间的区别.

See also Assembly difference between [var], and var for the difference between MASM and NASM syntax.

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

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