Illegal use of register in indirect addressing

前端 未结 1 817
北恋
北恋 2020-12-04 01:15

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

相关标签:
1条回答
  • 2020-12-04 01:46

    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.

    The 80386 addressing modes were extended towards more orthogonal:

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

    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.

    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
    

    See also purpose of LEA instruction.

    0 讨论(0)
提交回复
热议问题