Search code examples
assemblyadditionx86-16mov

How to make x=2a+3b in 4 instructions limit using ONLY mov,add,sub,neg?


Let's say x is a register which its value isn't known. I have to make x=2a+3b where a and b have unknown values.

I can use the 8086 asm instructions mov, add, sub, neg only. The use of the mul instruction isn't allowed, and also there is a limit of 4 instructions only.

Is it even possible?


Solution

  • Rewrite your expression:

    2a + 3b = 2(a + b) + b = (a + b) + (a + b) + b
    

    Note that you only need to compute the value of (a + b) once.