8. Write the corrected version of the following assembly code. Your corrected ve
ID: 3599519 • Letter: 8
Question
8. Write the corrected version of the following assembly code. Your corrected version should preserve the functions main, func1, and func2 and also ensure that their main operations do not change. Please pay special attention to the line comments below main: addi a0, $0, 20 addi al, $0, 45 addi $s3, $a0, 6 #do not change this line jal funcl add $s1, $v0, $s3 #$s3 needs to be $a0+6 as in line 3 func1: addi $s3, a0, 50 add $a2, $s3, $al jal func2 addi v0, vl, a0 ir ra #do not change this line #do not change this line func2: addi vl, $a2,100 jr raExplanation / Answer
The key here is to know what jal does.
Jump and link.
jal label
Copies the address of the next instruction into the register $ra and then jumps to the address label. Importantly, the changes made in the function "label" will be permanent i.e. when you go back to the original function the changes made in this function will be shown in the original as well.
So, if we need to $s3 need to be $a0+6 we need to store the $s3 value before jumping to func1 in another variable so that we can use it after. Simply, add the lines :
add $a3,$s3,$0 #storing s3 value in a3
jal func1 #now jump
add $s3,$a3,$0 # restore value of s3
add $s1,$v0,$s3 # now add as required.
-------------------------
Hope this helps. Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.