#C3545. Compute LEA Instructions
Compute LEA Instructions
Compute LEA Instructions
You are given a set of n integers. Your task is to generate a sequence of lea
assembly instructions that computes a sum using the eax and ebx registers.
The instructions are generated as follows:
- The first instruction is of the form $$\texttt{lea ebx, [\;a\times eax]}$$ where a is the first number in the input.
- Each subsequent instruction for an integer b (with
b = numbers[i]
fori \ge 1
) is of the form $$\texttt{lea ebx, [\;ebx + \lfloor b/2 \rfloor\times eax]}$$ where \( \lfloor b/2 \rfloor \) is the integer division of b by 2.
You need to output the total number of instructions followed by each instruction on a new line.
Assume that the initial value is stored in register eax and the first instruction loads the computed value into register ebx.
inputFormat
The first line contains an integer n
(1 ≤ n ≤ 1000) representing the number of integers. The second line contains n
space-separated integers.
Example:
3 2 3 7
outputFormat
The first line of output should be an integer k
representing the number of instructions (which will be equal to n
), followed by k
lines, each containing one assembly instruction.
Example:
3 lea ebx, [2*eax] lea ebx, [ebx + 1*eax] lea ebx, [ebx + 3*eax]## sample
1
5
1
lea ebx, [5*eax]
</p>