16位汇编代码中的OFFSET是什么意思? [英] What does OFFSET in 16 bit assembly code mean?
问题描述
我正在查看一些16位实模式的示例汇编代码.
I am going through some example assembly code for 16-bit real mode.
我遇到了麻烦:
mov bx, cs
mov ds, bx
mov si, OFFSET value1
pop es
mov di, OFFSET value2
这是做什么的?那里有"OFFSET"有什么作用?
what is this doing? What does having 'OFFSET' there do?
推荐答案
正如其他一些答案所说,offset
关键字是指与定义该段的段的偏移量.但是请注意,段可能会重叠,一个段中的偏移可能会与另一段中的偏移不同.例如,假设您在实模式下具有以下细分
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 mode
data SEGMENT USE16 ;# at segment 0200h, linear address 2000h
org 0100h
foo db 0
org 01100h
bar db 0
data ENDS
汇编器会看到foo
与data SEGMENT
的底距偏移0100h
,因此无论在什么位置看到offset foo
,它都会将值0100h
放入,而不管DS
的值是多少.时间.
The assembler sees that foo
is at offset 0100h
from the base of data SEGMENT
, so wherever it sees offset foo
it will put the value 0100h
, regardless of the value of DS
at the time.
例如,如果我们将DS
更改为data
段的基数以外的其他值,则汇编程序将假定:
For example, if we change DS
to something other than the base of the data
segment the assembler is assuming:
mov ax, 200h ; in some assemblers you can use @data for the seg base
mov ds, ax
mov bx, offset foo ; bx = 0100h
mov byte ptr [bx], 10 ; foo = 10
mov ax, 300h
mov ds, ax
mov bx, offset foo ; bx = 0100h
mov byte ptr [bx], 10 ; bar = 10, not foo, because DS doesn't match what we told the assembler
在第二个示例中,DS
是0300h
,因此DS
指向的段的基数是03000h
.这意味着ds:[offset foo]
指向与02000h + 01100h
相同的地址03000h + 0100h
,该地址指向bar
.
In the second example DS
is 0300h
, so the base of the segment pointed to by DS
is 03000h
. This means that ds:[offset foo]
points to the address 03000h + 0100h
which is the same as 02000h + 01100h
, which points to bar
.
这篇关于16位汇编代码中的OFFSET是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!