Question: 1. Assume that the variables a, b, c, d, e, and f are stored in consecutive memory locations, and that a register, say $20, has

1. Assume that the variables a, b, c, d, e, and f are stored in consecutive memory locations, and that a register, say $20, has the address for variable a.

(a) For the C language expression f = a + b + c + d;, what is the corresponding

EMU8086 assembly code?

(b) Do the same for the C language expression e = a + (f - 7);

2. Write equivalent C code for the following EMU8086 assembler fragments:

(a) add f, g, h ; (f g+h)

(b) addi h, i, 1 ;(hi+1) sub f, g, h ;(fg-h)

3. Assume that variables f, g, h, i, and j are already stored in general purpose registers, say $s0 to $s4 respectively, and the addresses of the first element of arrays A and B are stored in index registers, say $s6 and $s7 respectively. Provide EMU8086 code.

(a) f=g+h+B[4]; (b) f = g - A[B[4]];

4. For the following, assume that variables a, b, and i are kept in general purpose registers and that a base register holds the base address of array D.

Write EMU8086 assembly code for the following C code fragments, try to minimize the number of assembly instructions:

(a) A simple for loop: for (i = 0; i < 10, i++) a += b;

(b) do the same thing for the following C code.

for (i = 0; i < 10, i+=2) {

D[i] = D[i] + 1; D[i+1] = D[i+1] + 1;

}

(c) A while loop with an array:

while (a < 10) {

D[a] = a + b; a += 1; // could also be a++; }

(d) An example of recursion:

int fib (int a, int b, int i) {

if (i == 0) return b; else return fib(a+b, a, i-1);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!