为什么我从mov ax,bx + si + 1得到零? [英] Why am I getting zero from mov ax, bx+si+1?
问题描述
mov ax,10
mov bx,4
mov si,ax
mov ax,bx+si+1
LEA ax,[bx+si+1]
当我将bx,si和1加在一起并移至ax时,结果为0. 在下一行中,当我使用LEA时,它可以工作并得到15.
When I add bx,si and 1 together and move to ax , the result is 0. At the next line, when I use LEA it works and I get 15.
为什么使用move时我会归零?
Why am I getting zero when using move?
推荐答案
您的问题是:为什么我会从mov ax,bx + si + 1获得零?".很难给您一个准确的答案,因为您忘记告诉您使用的是哪个编译器,并且您的代码段不包含数据段,因此我们看不到您的数据.我们可以做的是使用数据段中的一些数字来测试您的代码,然后查看结果:
Your question is : "Why am I getting zero from mov ax, bx+si+1?". It's hard to give you an accurate answer because you forgot to tell what compiler you are using and your code snippet doesn't include the data segment so we can't see your data. What we can do is to test your code with some numbers in the data segment and see the results :
.model small
.stack 100h
.data
xy db 0A0h,0A1h,0A2h,0A3h,0A4h,0A5h,0A6h,0A7h,0A8h,0A9h,0AAh,0ABh,0ACh,0ADh,0AEh,0AFh,0B0h
.code
mov ax, @data
mov ds, ax
mov ax, 10
mov bx, 4
mov si, ax
mov ax, bx+si+1 ;◄■■ #1 (EXPLANATION BELOW ▼)
LEA ax, [bx+si+1] ;◄■■ #2 (EXPLANATION BELOW ▼)
让我们说明一下这里发生的情况:
Let's illustrate what happens here:
这是怎么回事:
#1 由于存在基址寄存器(bx
)和索引寄存器(si
),因此总和被解释为内存寻址,因此代码将数据存入内存位置15.ax
寄存器大小为2个字节,因此结果是ax
从内存位置15开始获取2个字节,在我们的数据段中,这2个字节为0AFh
和0B0h
. al
是ax
的低字节,因此第一个字节(0AFh
)存储在那里,高字节ah
获取第二个字节(0B0h
),这就是ax
变为
#1 Because of the presence of a base register (bx
) and an index register (si
) the sum is interpreted as a memory addressing, so the code gets the data in memory location 15. ax
register size is 2 bytes, so the result is that ax
gets 2 bytes starting at memory location 15, in our data segment those 2 bytes are 0AFh
and 0B0h
. al
is the lower byte of ax
, so the first byte (0AFh
) stores there, the higher byte ah
gets the second byte (0B0h
), and this is how ax
becomes 0B0AFh
.
#2 我们说过,基址寄存器bx
和索引寄存器si
的存在被解释为内存寻址,因此[bx+si+1]
指向内存位置15(lea
代表load effective address
,其目的是从数据段内部获取地址.您的代码行将获取内存位置15(0AFh
)的有效地址,即15.
#2 We said that the presence of the base register bx
and the index register si
is interpreted as a memory addressing, so [bx+si+1]
points to memory location 15 (0AFh
). Instruction lea
stands for load effective address
, its purpose is to get an address from inside the data segment. Your line of code is getting the effective address of memory location 15 (0AFh
), which is 15.
如此多的理论需要证明,在这里是
So much theory requires a demonstration, and here it is:
接下来是EMU8086的屏幕截图: BLUE 箭头指向原始代码行, GREEN 箭头指向被解释的代码行(作为内存寻址),并且 RED 箭头显示寄存器ax
(B0AFh
)中的效果.
Next is a screenshot from EMU8086 : the BLUE arrow points to the original line of code, the GREEN arrow points to the line of code as it is been interpreted (as a memory addressing), and the RED arrow shows the effect in register ax
(B0AFh
).
现在为下一条指令截屏: BLUE 箭头指向原始代码行, GREEN 箭头指向被解释的代码行(注意,它与上一个相同),并且 RED 箭头显示了寄存器ax
(0Fh
)中的效果.
Now the screenshot for the next instruction : the BLUE arrow points to the original line of code, the GREEN arrow points to the line of code as it is been interpreted (notice it's identical to the previous one), and the RED arrow shows the effect in register ax
(0Fh
).
最后,让我们测试Visual Studio 2013中的代码:下一个屏幕截图证明mov ax, bx+si+1
无效,另一行给出的结果与EMU8086(ax
= 0FH
)相同:
Finally, let's test the code in Visual Studio 2013 : next screenshot proves that mov ax, bx+si+1
is invalid, and the other line gives the same result as EMU8086 (ax
=0FH
) :
所以,为什么从mov ax,bx + si + 1那里得到零?"因为您的数据段中的存储位置15可能为零.您可能以为bx+si+1
会给您一个正常的数字15,但是现在您知道使用基址和索引寄存器将被解释为内存寻址,因此您不会得到数字15,但是数据内部存储器位置15 .
So, "why are you getting zero from mov ax, bx+si+1?" Because you probably have a zero in memory location 15 inside your data segment. You maybe thought that bx+si+1
was going to give you a normal number, 15, but now you know that using base and index registers will be interpreted as memory addressing, so you don't get the number 15 but the data inside memory location 15.
这篇关于为什么我从mov ax,bx + si + 1得到零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!