在间接寻址中非法使用寄存器 [英] Illegal use of register in indirect addressing

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

问题描述

我正在尝试编写一个在 x86 程序集 (MASM) 中添加两个大数的子例程.数字由si 和di 寄存器指向,函数应该从右到左迭代,将每个数据字相加并传递进位,并将结果保存在di 中.要添加的数据字数由前一段代码决定.

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
...

不幸的是,当我尝试编译此代码时,我收到错误 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?

推荐答案

原始8086寻址方式仅限于下表中的组合:

     (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 寻址模式被扩展到更多正交:

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

这里的索引寄存器都是32位的,esp可以用来直接指向栈变量,缩放项有合法的值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

另见LEA 指令的目的.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆