Question

Convert the following code to assembly MIPS void checki() { int i = 0; while(i <...

Convert the following code to assembly MIPS

void checki()
{
int i = 0;
while(i < 10)
{
switch(i)
{
case 1:
i += 5;
break;
case 2:
i --;
break;
case 3:
i += 2;
break;
default:
i++;
}
}
}

void main()
{
checki();
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please find the below code,, which is converted into assembly mips...

.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.text
.align   2
.globl   _Z6checkiv
$LFB0 = .
.set nomips16
   .ent   _Z6checkiv
   .type   _Z6checkiv, @function
Z6checkiv:
   .frame   $fp,24,$31       # vars= 8, regs= 1/0, args= 0, gp= 8
   .mask   0x40000000,-4
   .fmask   0x00000000,0
   .set   noreorder
   .set   nomacro
   addiu   $sp,$sp,-24
$LCFI0:
   sw   $fp,20($sp)
$LCFI1:
   move   $fp,$sp
   movz   $31,$31,$0
$LCFI2:
   sw   $0,8($fp)
   b   $L2
   nop

$L7:
   lw   $2,8($fp)
   li   $3,2           # 0x2
   beq   $2,$3,$L5
   nop

   li   $3,3           # 0x3
   beq   $2,$3,$L6
   nop

   li   $3,1           # 0x1
   bne   $2,$3,$L9
   nop

$L4:
   lw   $2,8($fp)
   nop
   addiu   $2,$2,5
   sw   $2,8($fp)
   b   $L2
   nop

$L5:
   lw   $2,8($fp)
   nop
   addiu   $2,$2,-1
   sw   $2,8($fp)
   b   $L2
   nop

$L6:
   lw   $2,8($fp)
   nop
   addiu   $2,$2,2
   sw   $2,8($fp)
   b   $L2
   nop

$L9:
   lw   $2,8($fp)
   nop
   addiu   $2,$2,1
   sw   $2,8($fp)
$L2:
   lw   $2,8($fp)
   nop
   slt   $2,$2,10
   andi   $2,$2,0x00ff
   bne   $2,$0,$L7
   nop

   move   $sp,$fp
   lw   $fp,20($sp)
   addiu   $sp,$sp,24
   j   $31
   nop

   .set   macro
   .set   reorder
   .end   _z6checkiv
$LFE0:
   .size   _z6checkiv, .-_z6checkiv
   .ident   "GCC: (debian 4.4.5-8) 4.4.5"

Add a comment
Know the answer?
Add Answer to:
Convert the following code to assembly MIPS void checki() { int i = 0; while(i <...
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
  • Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void...

    Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void change_global(int value) { counter = counter + value; } void main() { change_global(5); change_global(10); }

  • How do i convert the following C program into MIPS assembly? int main(void) { int var1[4]...

    How do i convert the following C program into MIPS assembly? int main(void) { int var1[4] ={4, 7, 12, 5}; int var2[4]= {15, 3, 6, 14}; int result[4]={0}; for (int i=0 ; i< 4; i++) result[i] = var1[i] - var2[i]; }

  • its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program...

    its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...

  • How do i convert the following C program into MIPS assembly? int main(void) { short var1[4]...

    How do i convert the following C program into MIPS assembly? int main(void) { short var1[4] ={5, 8, 13, 6}; short var2[4]= {16, 4, 7, 15}; short result[4]={0}; for (int i=0 ; i< 4; i++) result[i] = var1[i] - var2[i]; }

  • I need MIPS code for this program Translate the following C++ program to MIPS assembly program...

    I need MIPS code for this program Translate the following C++ program to MIPS assembly program (Please explain each instruction of your code by a comment and submit a .asm file) // Example program #include <iostream> #include <string> using namespace std; int main() { const int ADULT_CHOICE= 1, CHILD_CHOICE= 2, SENIOR_CHOICE= 3, QUIT_CHOICE= 4, ADULT = 250, CHILD = 200, SENIOR = 350; int choice, months; int charges = 0; do { cout <<"\n\t\tHealth Club Membership Menu\n\n" <<"1. Standard Adult...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4,...

    MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value

  • 5. Consider the following C code: int main() int x = 1; switch (x) case 1:...

    5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, answer the following: (a) Convert the above C code to MIPS assembly. (b) The condition you are testing is met at Case 1. You do not want the Case 2 to be tested. Add appropriate instructions in MIPS for this implementation. (c) If int x is any integer other than 1 or 2, you...

  • B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: ...

    B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write MIPS assembly code segment for the following C code snippet for (i - 0, i < 100; i++) -array Register assignment: i-) $ao Base of array -> $s0 array [ i+1] [i] / 2; B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write...

  • MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i...

    MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function

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