Question: *For this assignment I just need question #4* 2. (10 p.) Suppose that the target assembly language for a compiler has these 5 instructions (same

*For this assignment I just need question #4*

2. (10 p.) Suppose that the target assembly language for a compiler has these 5 instructions (same as in the book on page 61).

load address, reg

add reg, reg, reg

sub reg, reg, reg

mul reg, reg, reg

store reg, address

There are three registers r1, r2, r3, each arithmetic instructions takes the left operand from the first register, the right operand from the second register, and places the result in the third register (same as in the book). Translate the following assignments. Standard precedence and associativity rules apply. Process the variables in the same order as they appear in the assignments.

(a) total := a + b c + d

(b) result:= a b + (c d)

3. (10 p.) Suppose that the target assembly language for a compiler has these 5 instructions (same as in the book on page 62).

push address

add

sub

mul

pop address

Each arithmetic instruction pops an integer into the right operand, then pops an integer into the left operand and pushes the result of the operation on the stack. Translate the following assignments. Standard precedence and associativity rules apply. Process the variables in the same order as they appear in the assignments.

(a) total := a + b c + d

(b) result a b + (c d)

4. (6 p.) Give an example of an assignment statement that cannot be translated into the assembly language of Problem 2 because of shortage of registers. Translate your statement into the assembly language of Problem 3. Again, standard precedence and associativity rules apply. Process the variables in the same order as they appear in the assignments.

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!