Question

C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...

C to MIPS Conversion
C variable
   h
   i
   j
   k
   x
int a[] or &a[0]
MIPS register replacement
   $s0
   $s1
   $s2
   $s3
   $s4
   $a0
Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE).  Answer MUST use true 32-bit MIPS  instructions:

 Note that all variables (h,i,j,x,a[]) are 32-bit signed integers.
while ( h < 3 ) {
  a[j++]= 0;
  x = i >> 3;  
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note :- I have used addi instead of li and slt and beq instead bge . No pseudo code is used. Please change the rating in the previous too. It will be helpful. Any issue please comment, I will try to help you better. Thank you

Given register file:
h = $s0
i = $s1
j = $s2
k = $s3
x = $s4
&a[0] = $a0

MIPS PROGRAM :-

#while (h<3)
WHILE_LOOP:
addi $t0, zero, 0
slti $t0, $s0, 3
beq $t0, $zero, EXIT_WHILE

#calculating address of a[j]
sll $t0, $s2, 2
add $t0, $t0, $a0
  
#a[j]=0
sw $zero,0($t0)
  
addi $s2, $s2, 1 #j++

srl $s4, $s1, 3 #x=i>>3
j WHILE_LOOP
EXIT_WHILE:

Add a comment
Know the answer?
Add Answer to:
C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...

    C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];

  • For C to MIPS Conversion C variable h i j k x int a[] or &a[0]...

    For C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. No credit for pseudo-MIPS instructions (e.g., BGE). The answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];

  • For C to MIPS Conversion C variable h i j k int a[] or &a[0] MIPS...

    For C to MIPS Conversion C variable h i j k int a[] or &a[0] MIPS register replacement $50 $s1 $s2 $53 $54 $a0 Translate to MIPS. No credit for pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,ij.x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++] = 0; x = i >> 3; ܒܝܢ

  • For C to MIPS Conversion C variable h i j k X int a[] or &a[0]...

    For C to MIPS Conversion C variable h i j k X int a[] or &a[0] MIPS register replac ement $50 $51 $s2 $s3 $54 $a0 Translate to MIPS. No credit for pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,i,j,x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++] = 0; x = i >> 3; }

  • For C to MIPS Conversion h i u. k х C variable int a[] or &a[0]...

    For C to MIPS Conversion h i u. k х C variable int a[] or &a[0] $50 $51 $52 $s3 $54 $a0 MIPS register replacement Translate to MIPS. No credit for pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: if(j <k) a[j] = 1; else j = a[j];

  • Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of...

    Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of MIPS instructions to accomplish the required computation. (8 Points) 1) bgt $t1, 100, Label # bgt means branch if greater than 2) ble $s2, 10, Next # ble means branch if less than or equal 3) ror $s0, $s4, 7 # ror means rotate right $s4 by 7 bits and store the result in $s0 4) neg $s5, $s4 # $s5 will have the...

  • Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Register...

    Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Register allocations - i $s0 - j $s1 - base of A[] $s2 - base of B[] $s3 2) A[3] = B[i] + B[j]; 3) i = 0; while (j != A[i]) { i++; }

  • Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a...

    Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds the base address of the integer array D. Comments are required. for(i=1; i<a; i++) for(j=1; j<b; j++) D[2*j] = i + j;

  • 2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f,...

    2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Assume that the elements of the arrays A and B are 4-byte words: fAlBg

  • Implement the following pseudo instructions using the appropriate MIPS instructions: Divi $s0, $s1, imm (imm is...

    Implement the following pseudo instructions using the appropriate MIPS instructions: Divi $s0, $s1, imm (imm is a 16-bit value) Mul $s1, $s2, imm (imm is a 16-bit value) Li $t0, imme (load the 32-bit value into register $t0) Blt $to, imme, L (imm is a 16-bit value) Divu $s0, $s1, $s2

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT