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...

1 answer below »
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="">
Answered Same DayApr 26, 2021

Answer To: CS120 Midterm 2 Page Midterm II CS120 Spring 2021 Due Date 11:59 p.m., Tuesday, April 27th Hello...

Swapnil answered on Apr 27 2021
160 Votes
1
    The MIPS register can have the smaller instruction codes that are used for the 4 gigabyte memory
capacity. The MIPS register use convention can be specifying that the first 4 parameters used to the register set. The register can be theoretically can be used for the any purpose so it can give the MIPS name and number so it can specify the registers.
    2
    The subroutine is basically gives the block of code that can perform the task based on the same argument and it can give the optimally returns as the result. By the convention the register R0 to R3 to passing the arguments to the subroutine and the R0 will pass the result to the callers.
    3
    According to the MIPS conventions there are more than 4 arguments and the current subroutine stores on the stack and it uses the address sp+16, sp+20, sp+24 etc. The registers of the stack frame can contains the space to saving the values of the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here