6

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?

Necrolis
  • 25,836
  • 3
  • 63
  • 101
Lior
  • 5,841
  • 9
  • 32
  • 46

1 Answers1

10

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.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • 2
    just for reference this is common sub-expression elimination combined with algebraic reduction (reduction followed by CSE), just incase the OP wants to do further research. – Necrolis Oct 03 '12 at 20:38
  • Thank you, now I figured it out. – Lior Oct 03 '12 at 20:44