如何在EBX寄存器中存储连续字节
我试图将斐波那契序列的数组存储在 EBX 寄存器的连续字节中,从最低字节到最高字节。到目前为止,我的代码按预期工作:
fib0=0
fib1=1
fib2= fib0 + fib1
fib3= fib1 + fib2
fib4= fib2 + fib3
fib5= fib3 + fib4
fib6= fib4 + fib5
.data
array BYTE fib2, fib3, fib4, fib5, fib6 ;Adding elements to the array
.code
main PROC
xor ebx,ebx
xor esi,esi
mov esi,OFFSET array ; Moves array in to ESI for offset
inc esi ; incrementing to fib3 value
mov bl,[esi] ; fib3 going to bl registry
inc esi ; inc. to fib4 value
mov bh,[esi] ; fib4 going to bh registry
当我执行 EBX=00000302 的 DumpRegs 时。当我尝试将 fib5 移动到 bx 注册表时,它似乎覆盖了其他两个 bl 和 bh 注册表值。因此,当我使用以下代码将另外两个 fib 值写入 ebx 注册表时:
inc esi ; inc. to fib5 value
mov bx,[esi] ; fib5 going to bx registry
inc esi ; inc. to fib6 value
mov ebx,[esi] ; fib6 going to ebx registry
EBX=00000008 的最终值意味着最终的 mov 语句完全覆盖整个寄存器。我希望它看起来像连续字节中的 EBX=08050302 。这可能吗?
I am trying to store an array of the the fibonacci sequence in consecutive bytes of the EBX register from lowest byte to highest byte. My code works as expected up until this point:
fib0=0
fib1=1
fib2= fib0 + fib1
fib3= fib1 + fib2
fib4= fib2 + fib3
fib5= fib3 + fib4
fib6= fib4 + fib5
.data
array BYTE fib2, fib3, fib4, fib5, fib6 ;Adding elements to the array
.code
main PROC
xor ebx,ebx
xor esi,esi
mov esi,OFFSET array ; Moves array in to ESI for offset
inc esi ; incrementing to fib3 value
mov bl,[esi] ; fib3 going to bl registry
inc esi ; inc. to fib4 value
mov bh,[esi] ; fib4 going to bh registry
When I do a DumpRegs of EBX=00000302. When I then try to move fib5 to the bx registry it seems to over write the other two bl and bh registry values. So when I write the other two fib values to the ebx registry with the following code:
inc esi ; inc. to fib5 value
mov bx,[esi] ; fib5 going to bx registry
inc esi ; inc. to fib6 value
mov ebx,[esi] ; fib6 going to ebx registry
My final value for EBX=00000008 which means that final mov statement is completely overwriting the whole register. I would like for it to look like this EBX=08050302 in consecutive bytes. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将值写入寄存器时,它从寄存器的最低位开始。没有办法在不访问低位的情况下访问高位,除了带有
ah
、bh
、ch
的第二个字节,和dh
。您可以通过在每次存储后将寄存器右移 8 位来实现您想要的目的,这会将低字节移至高字节,并将其他字节移至 1。When you write a value into a register, it starts at the lowest bits of the register. There is no way to access the high bits without accessing the lower ones, with the exception of the second byte with
ah
,bh
,ch
, anddh
. You could do what you want by rotating the register right 8 bits after each storage, which will move the low byte to the high byte and the other bytes down 1.试试这段代码:
当然,由于每个值占用一个字节 = 8 位,而 EBX 的大小为 4 个字节(= 32 位),因此您不能将超过 4 个字节大小的值放入 EBX 中。
我不知道你真正想做什么,但这里有一个很好的例子,如何将四个字节大小的值打包到 EBX 寄存器中。
您应该注意,BL = EBX 的 8 个低位,BX = EBX 的 16 个低位。
换句话说:
BL = EBX 的位[7..0]。
BH = EBX 的位[15..8]。
BX = EBX 的位[15..0]。
Try this code:
Of course, since each value takes one byte = 8 bits, and size of EBX is four bytes (=32 bits), you cannot put more than 4 byte-sized values into EBX.
I have no idea what you really want to do, but here is a good exampe, how to pack four byte-sized values into EBX register.
You should note, that BL = 8 low bits of EBX, and BX = 16 low bits of EBX.
In other words:
BL = bits[7..0] of EBX.
BH = bits[15..8] of EBX.
BX = bits[15..0] of EBX.