Question
MIPS ISA 1. (10 points) Pseudo-instructions can be implemented using MIPS real instructions. For example: Provide a sequence of MIPS instructions that implement each of
MIPS ISA
1. (10 points) Pseudo-instructions can be implemented using MIPS real instructions. For example:
Provide a sequence of MIPS instructions that implement each of the pseudoinstructions below. You are NOT allowed to use any pseudo-instruction in your answer. You must comment your code well to explain the idea/algorithm. Register $at is recommended to use for pseudo-instruction implementations.
1) xchg reg1, const(reg2)
# exchange the contents of reg1 and the word at the
# memory location specified by the sum of const and the
# contents of reg2
2) lzcnt rdest, rsrc
# count the number of leading zero bits in register
# rsrc and put the count into register rdest
2. (6 pts) Consider the following MIPS code:
1) Assuming that $t1 = 20 and $s2 = 0 initially. What is the final value of $s2? You need to show your calculation.
2) Assuming that $t1 = 20 and $s2 = 0 initially. How many MIPS instructions will be executed for the given sequence? You need to show your calculation.
3. (10 pts) Assuming that we are executing an instruction at address 0x0040 1000:
1) If the instruction word is 0x8E08 0010, what is the address of the next instruction we will fetch and execute?
2) If the instruction word is 0x1252 01A5, what is the address of the next instruction we will fetch and execute?
3) If the instruction word is 0x0800 A018, what is the address of the next instruction we will fetch and execute? Show calculation steps to justify your answer.
4. (14 points) Translate function foo into MIPS assembly language. You must follow MIPS register usage conventions for function calls/returns as discussed in class. Check the Appendix of this document for a quick reference. Assume the function declaration of bar is int bar(int x); and a label bar marks the starting point of its function body. You can assume that function bar follows the same MPS conventions but do NOT need to implement it. You need to comment you code to get full credit for this question.
Pseudo -instruction Definition mov rdest, rsrc Implementation Copy value from register add rdest, rsrc, $e rsrc to register rdest LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE addi $t1, $t1, -2 addi $s2, $s2, 1 j LOOP DONE void foo(int *vals) while (bar *vals) vals++; Pseudo -instruction Definition mov rdest, rsrc Implementation Copy value from register add rdest, rsrc, $e rsrc to register rdest LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE addi $t1, $t1, -2 addi $s2, $s2, 1 j LOOP DONE void foo(int *vals) while (bar *vals) vals++Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started