Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 733
Lior Avatar asked Oct 03 '12 20:10

Lior


People also ask

How does MOV instruction work?

The MOV instruction moves data bytes between the two specified operands. The byte specified by the second operand is copied to the location specified by the first operand. The source data byte is not affected.

What are EAX EBX ECX EDX registers?

The EAX, EBX, ECX, EDX, EBP, EDI, and ESI registers are all 32-bit general-purpose registers, used for temporary data storage and memory access. Some of CPU instructions modify specific registers.


1 Answers

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.

like image 200
Ted Hopp Avatar answered Sep 19 '22 10:09

Ted Hopp