Search code examples
assemblyx86-16mov

Assembly 8086: Summing 2 registers with MOV and LEA only


My task is to sum AX and BX to AX, without using "MOV" or "LEA" operands. I am bit stuck here, can you help me please?

; AX need to be 15, using ONLY 'mov' and 'lea'. 
; Do NOT use arithmetic instrutions (add, inc, mul, etc.)

    mov     ax,10
    mov     bx,4

    lea cx,ax
    lea cx, [cx+bx]  

What am i doing wrong? sorry for my mistakes, i am a newbie.


Solution

  • The not so obvious thing about lea in 16-bit addressing mode today is that not any register can be used as src operand. If I recall correctly, you can only add base pointer (bp) or index (bx) to source or destination index (si or di) registers. dest operand can be any general-purpose register.

    The following are allowed:

    lea ax, [si + bx]
    lea ax, [di + bx]
    lea ax, [si + bp]
    lea ax, [di + bp]
    

    At this point I believe you've already got how to do the task:

    mov si, ax        ; si = ax
    lea ax, [si + bx] ; ax = ax + bx