Pointers and Indexes in Intel 8086 Assembly

孤者浪人 提交于 2019-12-08 04:25:59

问题


I have a pointer to an array, DI.

Is it possible to go to the value pointed to by both DI and another pointer?

e.g:

mov bl,1           
mov bh,10
inc [di+bl]
inc [di+bh]

And, on a related note, is there a single line opcode to swap the values of two registers? (In my case, BX and BP?)


回答1:


For 16-bit programs, the only supported addressing forms are:

[BX+SI]
[BX+DI]
[BP+SI]
[BP+DI]
[SI]
[DI]
[BP]
[BX]

Each of these may include either an 8- or 16-bit constant displacement.

(Source: Intel Developer's Manual volume 2A, page 38)

The problem with the example provided is that bl and bh are eight-bit registers and cannot be used as the base pointer. However, if you set bx to the desired value then inc [di+bx] (with a suitable size specifier for the pointer) is valid.


As for swapping "the high and low bits of a register," J-16 SDiZ's suggestion of ror bx, 8 is fine for exchanging bl and bh (and IIRC, it is the optimal way to do so). However, if you want to exchange bit 0 of (say) bl with bit 7 of bl, you'll need more logic than that.




回答2:


DI is not a pointer, it is an index.

You can you ROR BX, 8 to rotate a lower/higher byte of a register.



来源:https://stackoverflow.com/questions/3384346/pointers-and-indexes-in-intel-8086-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!