本文介绍了在间接非法使用寄存器寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个子程序,在x86汇编(MASM)增加了两个大的数字。的数字,指出在由Si和二寄存器和函数应从右到左迭代,将每个数据字,并通过进位和保存的结果二。补充的是由code的previous块确定的数据字的数目。

I'm trying to write a subroutine that adds two large numbers in x86 assembly (MASM). The numbers are pointed at by the si and di registers, and the function should iterate from right to left, adding each data word and passing the carry, and saving the result in di. The number of data words to add is determined by a previous chunk of code.

...
    mov       cx, ( number of data words to add )
adding:
    mov       bx,cx               ;copy the loop counter to bx
    lea       ax,[di+2*bx]        ;move ax to the destination word
    adc       ax,[si+2*bx]        ;add the source word into the destination word
    loop      adding              ;main sub loop
...

不幸的是,当我尝试编译此code,我得到错误A2032:在Lea和ADC都行使用无效寄存器。有什么不对,我使用?

Unfortunately, when I try to compile this code, I get error A2032: invalid use of register on both the lea and adc lines. What is wrong with the syntax that I'm using?

推荐答案

的仅限于本组合图表中:

The original 8086 addressing modes are limited to the combinations in this chart:

     (disp)   (base)   (offset)
 mov [1234] + [bx]  +  [si], ax
              [bp]  +  [di]

必须选择从每组最多一个项目(位移,基础和偏移量)。没有其他的组合是有效的。

One must choose maximum of one item from each group (displacement, base and offset). No other combination is valid.

进行了扩展转向更正交80386寻址模式

The 80386 addressing modes were extended towards more orthogonal:

 mov  al, byte ptr [12345] + [esp + 8 * eax];

下面索引寄存器都是32位的,尤其可用于直接指向堆栈变量和定标项有这么多的组合1,2,4和8合法值的指令 LEA 可用于执行单指令的正交的3-参数除了不改变国旗:[REG1] = [REG2] + [REG3];并执行一些其它算法,诸如通过3,5-或9乘以系数寄存器。

Here the index registers are all 32-bit, esp can be used to point directly to stack variables, and the scaling term has legal values of 1,2,4 and 8. With this many combinations the instruction LEA can be used to perform a single instruction orthogonal 3-parameter addition without changing flags: [reg1] = [reg2] + [reg3]; and to perform some other arithmetic, such as multiplying register by a factor of 3,5 or 9.

无32位寻址模式之一有例如模拟缩放以

Without 32-bit addressing modes one has to emulate the scaling e.g. with

     mov bx, (N-1)*2          // constant expression
 a:  mov ax, [bx + di]
     adc ax, [bx + si]
     sub bx, 2
     jns a

另请参阅的href=\"http://stackoverflow.com/questions/1658294/whats-the-purpose-of-the-lea-instruction\">目的。

See also purpose of LEA instruction.

这篇关于在间接非法使用寄存器寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!