Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate the following C code into MIPS code. if(i==0) { I=i+1; } B[2]=B[4]; As

ID: 3649424 • Letter: T

Question

Translate the following C code into MIPS code.
if(i==0)
{
I=i+1;
}
B[2]=B[4];
Assume B is an array of integers, and that the compiler associates the variable i to the register $s1.
Also, assume that the beginning address of array B is stored in register $s2.



Translate the following C code into MIPS code.
for (i=0; i<5; i=i+1)
{
A[i]=A[i+1];
}

Assume A is an array of characters and its address is stored into register $4. Also, assume that the compiler associates the variable I to the register $5.

Explanation / Answer

.text .globl main main: #create the array la $9,a #load address of the array addi $8,$0,5 #value to store sw $8,0($9) #store data in array a[0]=5 addi $9,$9,4 #next element addi $8,$0,5 #value to store sw $8,0($9) #store data in array a[1]=5 addi $9,$9,4 #next element addi $8,$0,5 #value to store sw $8,0($9) #store data in array a[2]=5 addi $9,$9,4 #next element addi $8,$0,6 #value to store sw $8,0($9) #store data in array a[3]=6 addi $9,$9,4 #next element addi $8,$0,7 #value to store sw $8,0($9) #store data in array a[4]=7 addi $9,$9,4 #next element add $14,$0,$0 #res=0; addi $16,$0,10 #n=5; addi $17,$0,5 #x=5; add $18,$0,$0#i=0; in order to start loop from 0 la $9,a #load address of the array loop: #for lw $15 ,0($9) #a[i] addi $9,$9,4 #next element bne $15,$17,notequal addi $14,$14,1 #res=res+1; notequal: addi $18, $18, 1 # i=i+1; bne $18, $16, loop #next #print result addi $2,$0,4 la $4,str1 syscall #count= addi $2,$0,1 add $4,$0,$14 syscall# res Hope that helps :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote