Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write the following C code in MIPS assembler: x = x + y + z - q; Assume that x, y, z, q are

1. Write the following C code in MIPS assembler: x = x + y + z - q; Assume that x, y, z, q are stored in registers $s1-$s4. 2. Describe the difference between carry and overflow. For each of the following, state if it is a carry, an overflow, or neither. (a) 1011 + 0111 (unsigned) (b) 0111 + 0010 (unsigned) (c) 0111 + 0010 (signed) (d) 1000 + 0111 (signed) 3. Convert the C function below to a MIPS assembly language subroutine. Then write code that calls the subroutine (assuming that n is in $a0) and stores the return value in $v0. unsigned int func(unsigned int n) { if (n == 0) return 0; else return n - 1; } 4. Use the register values below for the next questions. Assume each of the following questions starts from the original values; that is, DO NOT use value changes from one question as propagating into future parts of the question. $s0=5 $s1=6 $s2=7 (a) Give the values of $s0, $s1 and $s2 after this instruction: add $s0, $s1, $s2 (b) Give the values of $s0, $s1 and $s2 after this instruction: sub $s0, $s2, $s1 (c) Give the value of $s0 after this instruction: addi $s0, $s0, -1 5. Write instructions to push $s0 to the stack and instructions to pop it off. PUSH: POP: 6. Convert -67 and 42 into binary, using twos decimal representation for the negative number. Add the numbers. Convert the result back to decimal. Show all your work. 7. Fill in the immediate field in the ORI instruction below to force bits 5 and 7 of $t0 to be 1, while leaving all other bits unchanged. ORI $t0, $t0, 0x_________________ 8. What does the following code do? Rewrite the code using sll instead of add. add $t0, $t0, $t0 9. Write MIPS code to implement the following loop: for (i=0; i<3;i++) array[i] += 3; // assume address of array is in $s6, and $s3 = i which is initialized to zero 10. For each addressing mode, write a sample instruction using that mode. 11. (a) What is this MIPS statement: 0x012b8022 (b) Convert the following MIPS statement to machine/hex code: or $s0, $t2, $t5 Chapter 3 Questions 12. Write an add instruction to add the value in $t0 to $t1 and store it in $s0. Use an instruction that will not cause an overflow. 13. (a) Convert 35 to binary (b) convert -9 to binary (c) add the two numbers in binary. Assume all operands are 8 bits. 14. Write instruction(s) to multiply the value in $t0 by the value in $t1. Both may be 32 bits. 15. What is the difference between add and addu? 16. Describe how the hi/lo registers are used in multiplication.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago