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

Let's say x is a register whose value is unknown. I have to do x=2a+3b , where a and b have unknown values.

I can use the 8086 asm mov , add , sub , neg commands. Using the mul instruction is not allowed, and there is a restriction on only 4 commands.

Is it possible?

+6
source share
1 answer

Rewrite your expression:

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

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

+10
source

Source: https://habr.com/ru/post/926884/


All Articles