16位汇编代码中的OFFSET是什么意思?
我正在查看 16 位实模式的一些示例汇编代码。
我遇到了这样的问题:
mov bx, cs
mov ds, bx
mov si, OFFSET value1
pop es
mov di, OFFSET value2
这是在做什么?那里有“OFFSET”有什么作用?
I am going through some example assembly code for 16-bit real mode.
I've come across the lines:
mov bx, cs
mov ds, bx
mov si, OFFSET value1
pop es
mov di, OFFSET value2
what is this doing? What does having 'OFFSET' there do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如其他一些答案所说,
offset
关键字是指距定义它的段的偏移量。但请注意,段可能会重叠,并且一个段中的偏移量可能与另一段中的不同。例如,假设您在实模式下有以下段汇编器发现
foo
位于距data SEGMENT
基点的偏移量0100h
处,因此无论何时看到offset foo
,它都会输入值0100h
,而不管当时DS
的值是什么。例如,如果我们将
DS
更改为data
段基址以外的内容,则汇编程序会假设:在第二个示例中,
DS
为 < code>0300h,因此DS
指向的段的基址是03000h
。这意味着ds:[offset foo]
指向地址03000h + 0100h
,它与02000h + 01100h
相同,后者指向 <代码>栏。As some of the other answers say, the
offset
keyword refers to the offset from the segment in which it is defined. Note, however, that segments may overlap and the offset in one segment may be different in another segment. For instance, suppose you have the following segment in real modeThe assembler sees that
foo
is at offset0100h
from the base ofdata SEGMENT
, so wherever it seesoffset foo
it will put the value0100h
, regardless of the value ofDS
at the time.For example, if we change
DS
to something other than the base of thedata
segment the assembler is assuming:In the second example
DS
is0300h
, so the base of the segment pointed to byDS
is03000h
. This means thatds:[offset foo]
points to the address03000h + 0100h
which is the same as02000h + 01100h
, which points tobar
.它仅表示该符号的地址。这有点像 & C 中的运算符,如果您熟悉的话。
It just means the address of that symbol. It's a bit like the & operator in C, if you are familiar with that.
offset
表示si
寄存器将等于变量 value1 的偏移量(而不是其实际值)。偏移量是从存储变量的内存段开始的地址。偏移量通常相对于 ds 段(在您的情况下 ds 和 cs 寄存器指向同一段)。offset
means thatsi
register will be equal to the offset of the variable value1 (not to its actual value). Offset is the address from the beginning of memory segment where the variable is stored. The offset is usually relative tods
segment (in your caseds
andcs
registers are pointing to the same segment).在x86 16bit模式下,地址空间不是平坦的;相反,地址由偏移量和“段”组成。 “段”指向一个64K的空间,偏移量在该空间内。
请参阅http://en.wikipedia.org/wiki/Memory_segmentation
In x86 16bit mode, address space is not flat; instead, addresses are composed of an offset and a "segment". The "segment" points to a 64K space, offset is within that space.
See http://en.wikipedia.org/wiki/Memory_segmentation
来自 MASM 程序员指南 6.1(Microsoft 宏汇编器)
如果您仔细阅读,最终值是在您“链接”目标代码以创建 DLL/EXE 后确定的。在链接之前,您拥有的只是一个立即值,它表示距段基地址的偏移量。
From MASM Programmer's Guide 6.1 (Microsoft Macro Assembler)
If you read carefully, the final value is determined after you "link" your object code to create a DLL/EXE. Prior to linking, all you have is an immediate value which represents the offset from the segment's base address.
偏移基本上是距线段点(也称为基准点)的距离。
例如段地址是0000,偏移量或逻辑地址是0100,那么可以通过将两对相加来计算物理地址。
物理地址=0000+0100=0100
意味着我们需要的位置是0100这个地址。
类似地,如果段地址为 1DDD 并且偏移量为 0100,则:
物理地址是:1DDD+0100=1EDD
意味着我们的目的地是1EDD。
Offset is basically the distance from the segment point(also called datum point).
for example segment address is 0000 and the offset or logical address is 0100 then the physical address can be counted by adding the two pairs.
Physical Address = 0000+0100=0100
Means that our required location is on the address of 0100.
Similarly if segment address is 1DDD and offset is 0100 then :
Physical address is : 1DDD+0100=1EDD
Means that our destination is 1EDD.