Just answer the questions in a separate file, no need to worry about the github repository. Also, make sure the mips assembly runs in MARS ide
CS120 Midterm 2 Page Midterm II CS120 Spring 2021 Due Date 11:59 p.m., Tuesday, April 27th Hello all, As we complete the second exam, and come closer to the end of the semester, think back on everything you have learned this semester. You have learned basic C programming (I have to take an entire semester to teach it to CE majors). You have also learned basic assembly programming. That’s 2 entirely different languages in less than 3 months. You should be impressed with yourself. I certainly am. Now for the official part: Please make sure you follow ALL the instructions carefully. Failure to follow instructions will, at best, result in a large point deduction and could result in a 0 for the exam. Double check your submission (a couple times). I will not accept a late submission for ANY reason (even 1 second late). Plan ahead. This exam is your chance to show me what you have learned in this section of the course. Spend some time to make sure it’s the best you can do. Please note that following instructions and submitting properly is PART OF THE EXAM. A few notes: 1. You must complete the exams on your own. The exam is open book, open resource, but you cannot ask anyone else for help. a. Once again, if you cannot complete the exam on your own, you should probably consider a career in politics. I hear the primary qualification is an inability to think and willingness to cheat. · Assume $ preceding a symbol means it is a register. · Snippet variables with register names imply you should use that register. · For all questions, you should preserve the values in all registers used in subroutines ($s, $t, and $ra). · I know normally you do not need to preserve $t registers, but for this exam, you do. · Unless you are given specific registers, in which case you MUST use the given registers, you can use any appropriate register. A cheat sheet for the mips instructions can be found at the end of the test. You cannot use MIPS instructions that are not in the list below. 1. [1 point] Describe, in your own words, why MIPS registers have both a number and a name (i.e. $t0 is register 8)? 2. [1 point] Which registers can be used to pass arguments to a subroutine? 3. [2 points] According to MIPS conventions, which registers must be saved on the stack in a subroutine? 4. [5 points] a. [2 points] Describe, in your own words, the difference between the addi and add instruction in MIPS. b. [1 point] What is a pseudo-instruction in MIPS? c. [2 points] What is an Assembly Directive? Use the .asciiz and .text directives as examples for your explanation. 5. [4 points] Convert the following C program code into the MIPS assembly language equivalent: int main(){ int s0 = 1, s1 = 1; if (s1 == s0) int s3 = 1; else int s2 = s0 + s1; return 0; } 6. [3 points] Convert the following C program into the MIPS assembly language equivalent int main(){ int s1 = 1, s2 = 5; if (s2 < s1) s1 = 0xf; return 0; } 7. [10 points] write a complete program in mips assembly that is the equivalent to the following c code. you must follow mips conventions and ensure that any $t and $s registers used in subroutines are preserved on the stack (regardless of whether or not they are used elsewhere). int bar(int t){ t = t & 2; if(t == 10) t = t + 10; return t; } int main(){ int s = bar(8); printf(“%d”, s); char str[] = “done with mips!” printf(“%s\n”, str); return 0; } submission write your answers in a plain text file called ‘midtermii.txt’. submit your exam by saving the file in this repo, and pushing it to github. submit the commit hash for the version you would like graded on mycourses. using the standard submission process we have used for assignments up to this point in the course is part of the exam, so please make sure you double check your submission. s1)="" s1="0xF;" return="" 0;="" }="" 7.="" [10="" points]="" write="" a="" complete="" program="" in="" mips="" assembly="" that="" is="" the="" equivalent="" to="" the="" following="" c="" code.="" you="" must="" follow="" mips="" conventions="" and="" ensure="" that="" any="" $t="" and="" $s="" registers="" used="" in="" subroutines="" are="" preserved="" on="" the="" stack="" (regardless="" of="" whether="" or="" not="" they="" are="" used="" elsewhere).="" int="" bar(int="" t){="" t="t" &="" 2;="" if(t="=" 10)="" t="t" +="" 10;="" return="" t;="" }="" int="" main(){="" int="" s="bar(8);" printf(“%d”,="" s);="" char="" str[]="“Done" with="" mips!”="" printf(“%s\n”,="" str);="" return="" 0;="" }="" submission="" write="" your="" answers="" in="" a="" plain="" text="" file="" called="" ‘midtermii.txt’.="" submit="" your="" exam="" by="" saving="" the="" file="" in="" this="" repo,="" and="" pushing="" it="" to="" github.="" submit="" the="" commit="" hash="" for="" the="" version="" you="" would="" like="" graded="" on="" mycourses.="" using="" the="" standard="" submission="" process="" we="" have="" used="" for="" assignments="" up="" to="" this="" point="" in="" the="" course="" is="" part="" of="" the="" exam,="" so="" please="" make="" sure="" you="" double="" check="" your=""> s1) s1 = 0xf; return 0; } 7. [10 points] write a complete program in mips assembly that is the equivalent to the following c code. you must follow mips conventions and ensure that any $t and $s registers used in subroutines are preserved on the stack (regardless of whether or not they are used elsewhere). int bar(int t){ t = t & 2; if(t == 10) t = t + 10; return t; } int main(){ int s = bar(8); printf(“%d”, s); char str[] = “done with mips!” printf(“%s\n”, str); return 0; } submission write your answers in a plain text file called ‘midtermii.txt’. submit your exam by saving the file in this repo, and pushing it to github. submit the commit hash for the version you would like graded on mycourses. using the standard submission process we have used for assignments up to this point in the course is part of the exam, so please make sure you double check your submission.>