75.6k views
5 votes
Write a program to evaluate the arithmetic expression: (13x - 4xy + 18)/7

Use symbolic addresses x, y, answer, and remainder. Put values for x and y in the .data section of your program followed by two locations for answer and remainder. Use two registers for x and y and load them from memory. At the end of the program, store the answer and remainder to memory. Assume that the values are small enough so that results fit into 32 bits. Since load delays are turned on in SPIM be careful what instructions are placed in the load delay slot. Verify that the program works by using several initial values for x and y. Use x=1, y=1 and x=1, y= -1 to start since this will make debugging easy. Then try some other values. Don’t assume that x and y are positive. Remember that a value loaded from memory can only be used after a one instruction delay slot. Also, be sure to use the basic assembly two-operand instructions for multiply and divide and to retrieve the results of the operation from the lo and hi registers. Use register $10 as a base register and use register-offset addressing to load and store values. Set up the base register with a lui instruction. The program at the end of chapter 15 will be useful.

1 Answer

6 votes

Final answer:

To write a program to evaluate the arithmetic expression (13x - 4xy + 18)/7 using symbolic addresses and registers for memory operations.

Step-by-step explanation:

To write a program to evaluate the arithmetic expression: (13x - 4xy + 18)/7, you need to use symbolic addresses x, y, answer, and remainder. Put values for x and y in the .data section of your program followed by two locations for answer and remainder.

Use two registers for x and y and load them from memory. At the end of the program, store the answer and remainder to memory.

Make sure to follow the rules for sign conventions when evaluating the expression. For example, when two positive numbers multiply, the answer has a positive sign, when two negative numbers multiply, the answer also has a positive sign, and when the two numbers multiplied have opposite signs, the answer has a negative sign.

User Paul Richter
by
7.7k points