edited by
1,653 views
4 votes
4 votes
The arithmetic expression

$$(a+b) * c- d/e ** l$$

is to be evaluated on a two address machine, where each operand is either a register or a memory location.

With a minimum number of memory accesses of operands.the number of registers required to evaluate this expression is ______.

The number of memory accesses of operands is ____________
edited by

3 Answers

3 votes
3 votes
Considering ** is for exponentiation.

3 registers are required & 6 memory operations in total to fetch all operands.
1 votes
1 votes

Assuming all operands are initially in memory, 6 memory operations are (at least) required to fetch all operands.

Also assuming that every ALU instruction(data manipulation instructions) is such that the first address in the instruction is destination as well as address of first operand. 

For eg : ADD R1, R2 means Register R1 is the destination as well as the address of first operand for addition operation.

Also assuming ** is exponentiation.

(So many assumptions.. very poorly framed question it is..But that year paper was subjective, so we could have assumed things and write what we assumed in the answer).

Now, we have two address machine, where each operand is either a register or a memory location.

Our first priority : Minimum memory accesses

Our Second priority : Minimum number of registers used.

So,

Let's bring operand 'a' into register r1 and let b stay in memory. So, 

ADD r1,b    (r1 <----a ;  r1 <---- (r1+b))   

MUL r1,c    (  (r1 <---- (r1 * c)) )

So, Now r1 has (a+b)*c.

  Let's bring operand e into register r2.  

Exp r2, l

Let's bring operand d into register r3.    (If it was $e^l/d$ then we would have not brought d into register But since d here is the first operand, we have to bring it to the register because first address in the instruction is destination as well as address of first operand.)

DIV  r3,r2

SUB  r1,r3

So, 3 registers.


NOTE that answer for expression 

$(a+b)∗c− e^l/d$ would be 2 registers.

0 votes
0 votes

To evaluate the given arithmetic expression (a+b)*c-d/e**l on a two-address machine with a minimum number of memory accesses for operands, we need to consider the number of distinct variables and their dependencies.

Let's analyze the expression:

  1. a and b are added.
  2. The result of the addition is multiplied by c.
  3. The product is subtracted from d.
  4. e is divided by the result of the subtraction.
  5. The final result is raised to the power of l.

To minimize memory accesses, we should use registers for intermediate values. Let's denote the registers as R1, R2, R3, and so on. The number of registers required is equal to the maximum number of distinct variables that are active simultaneously during the computation.

Here's a breakdown:

  • R1: a+b
  • R2: R1*c
  • R3: d-R2
  • R4: e**l/R3

So, we need a minimum of 4 registers (R1, R2, R3, R4) to evaluate this expression with a minimum number of memory accesses for operands.

Now, let's consider the number of memory accesses for operands. Each variable a, b, c, d, e, and l needs to be fetched from memory once, as there are no repeated occurrences in the expression.

Therefore, the number of memory accesses for operands is 6.

In summary:

  • Number of registers required: 4
  • Number of memory accesses for operands: 6

Related questions

0 votes
0 votes
3 answers
1
Kathleen asked Sep 12, 2014
1,913 views
Using the 8087 arithmetic coprocessor with the 8086 CPU requires that the 8086 CPU is operated ............
3 votes
3 votes
1 answer
2