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:

if(j < k )
  a[j] = 1;
else 
  j = a[j];
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note :- I have only used instead li I have used addi and instead of BGE I have used slt and beq. Please check and please change the rating in the previous one also please. Any issue please comment I can help you. And, if $zero gives compiler issues; then use $0 as it is depends on compiler

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

MIPS PROGRAM :-

IF_BLOCK:

#calculating address of a[j]
sll $t0, $s2, 2
add $t0, $t0, $a0
  
#if(j<k)
slt $t1, $s2, $s3 #checking for j<k;
beq $t1, $zero, ELSE_PART #if fails then else part

addi $t1, $zero, 1
sw $t1,0($t0) #a[j]=1

ELSE_PART:
lw $s2, 0($t0) #j=a[j]

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
  • 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];

  • 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; }

  • 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 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];

  • 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; }

  • 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 code into MIPS code. Test (int i, int j)                         {        &nbsp

    Translate the following code into MIPS code. Test (int i, int j)                         {                         int k;                         k = Double(i+1) + Double (j-10)                         return k;                         } Sub (int m)                         {                         int g;                         g = m + m;                         return g;                         } Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.

  • 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;

  • 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
ADVERTISEMENT