0

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.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Ilan Dajan
  • 19
  • 1
  • 10
  • Just use the `add` instruction. That's what it's for. There's no reason not to use it. – Raymond Chen Oct 02 '16 at 02:08
  • Your question is self-contradictory. Do you want to add without using mov and lea or only using mov and lea ? – Ian Cook Oct 02 '16 at 05:27
  • You should always include the exact error messages you're getting in your question. Or better, put the error message into a search engine. – Peter Cordes Oct 03 '16 at 10:19
  • Another potential duplicate: http://stackoverflow.com/questions/28648722/addressing-issue-with-mov-instruction-in-x86/28648811#28648811 – Peter Cordes Oct 03 '16 at 11:12

1 Answers1

5

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
Alexander Zhak
  • 9,140
  • 4
  • 46
  • 72
  • Usually you'd write it as base + index, not index + base. But yes, those are the only 4 pairs of registers allowed in 16-bit addressing modes. See also [available x86 addressing modes](http://stackoverflow.com/a/34058400/224132), which has some links to more details for 16-bit stuff, but it's mostly about 32/64-bit stuff. – Peter Cordes Oct 03 '16 at 10:18