Question

Write the corresponding MIPS assembly equivalent of the given Ccode. Assume that register $s0 contains the base address for a

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

.LC0:

        .word   3

        .word   -21

        .word   18

        .word   0

        .word   16

        .word   85

        .word   -44

        .word   23

        .word   100

        .word   -20

main:

        daddiu  $sp,$sp,-80

        sd      $fp,72($sp)

        move    $fp,$sp

        lui     $8,%hi(%neg(%gp_rel(main)))

        daddu   $8,$8,$25

        daddiu  $8,$8,%lo(%neg(%gp_rel(main)))

        li      $2,10                 # 0xa

        sw      $2,16($fp)

        ld      $2,%got_page(.LC0)($8)

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $4,%got_ofst(.LC0)($2)

        ldr     $4,7($3)

        move    $6,$4

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $4,8($3)

        ldr     $4,15($3)

        move    $5,$4

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $4,16($3)

        ldr     $4,23($3)

        daddiu  $3,$2,%got_ofst(.LC0)

        ldl     $7,24($3)

        ldr     $7,31($3)

        move    $3,$7

        daddiu  $2,$2,%got_ofst(.LC0)

        ldl     $7,32($2)

        ldr     $7,39($2)

        move    $2,$7

        sd      $6,24($fp)

        sd      $5,32($fp)

        sd      $4,40($fp)

        sd      $3,48($fp)

        sd      $2,56($fp)

        sw      $0,4($fp)

        sw      $0,8($fp)

        sw      $0,12($fp)

        sw      $0,0($fp)

        b       .L2

        nop

.L5:

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,24($2)

        lw      $3,4($fp)

        addu    $2,$3,$2

        sw      $2,4($fp)

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,24($2)

        blez    $2,.L3

        nop

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,24($2)

        lw      $3,8($fp)

        addu    $2,$3,$2

        sw      $2,8($fp)

.L3:

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,24($2)

        bgez    $2,.L4

        nop

        lw      $2,0($fp)

        dsll    $2,$2,2

        daddu   $2,$fp,$2

        lw      $2,24($2)

        lw      $3,12($fp)

        addu    $2,$3,$2

        sw      $2,12($fp)

.L4:

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

.L2:

        lw      $3,0($fp)

        lw      $2,16($fp)

        slt     $2,$3,$2

        bne     $2,$0,.L5

        nop

        move    $2,$0

        move    $sp,$fp

        ld      $fp,72($sp)

        daddiu  $sp,$sp,80

        j       $31

        nop

lw lw addu $2,24($2) $3,12($fp) $2,$3, $2 $2,12($fp) SW .L4: lw addiu $2,0($fp) $2,$2,1 $2,0($fp) SW .L2: lw slt bne $3,0($fp

Add a comment
Know the answer?
Add Answer to:
Write the corresponding MIPS assembly equivalent of the given Ccode. Assume that register $s0 contains the...
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
  • 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...

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

  • Convert the following C fragment to equivalent MIPS assembly language. Assume that the variables a, b,...

    Convert the following C fragment to equivalent MIPS assembly language. Assume that the variables a, b, c, d, i and x are assigened to registers $t1, $t2, $t3, $t4, $s0 and $s1 respectively. Assume that the base address of the array A and B is in register $a0 and $a1 respectively. if (a > 0)            b = a + 10;            else                b = a - 10;

  • what is the corresponding MIPS assembly code for the statements shown below that written in C....

    what is the corresponding MIPS assembly code for the statements shown below that written in C. Assume that the variables sum and n assigned to register $t1 and $t2 respectively, and the base address of the array A is in register $t0. int sum = 0 for(n=100 ; n>=0; n=n-5) { if(A[n]>0 sum = a[n] +3 }

  • For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold...

    For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold 16-bit integer values, $ s0 is the base for array X, $ s1 is the base for array Y, and $ t0 and $ t1 are index variables i and j respectively. Comment code X [j] = Y [i + j];

  • Translate the following C code to MIPS assembly code. Assume that the value of i is...

    Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i];

  • 1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume...

    1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...

  • 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

  • For the following C statement, what is the corresponding MIPS assembly code?

    For the following C statement, what is the corresponding MIPS assembly code?  Assume that the variables i, and j are assigned to registers $s0, $s1, respectively. Assume that the base address of the arrays A and B are in registers $s2 and $s3, respectively. B[i] = A[i] - 10

  • C3. Convert the following C-code to MIPS code. [Use register $al for the variable i, temporary re...

    C3. Convert the following C-code to MIPS code. [Use register $al for the variable i, temporary registers for other values, and load the base memory address of the array OxA0000080 to Şao] int i i int array [101; for (i= 0; i<5 ; i=i+1 ) { [i+1] [i] 8; * array = array C3. Convert the following C-code to MIPS code. [Use register $al for the variable i, temporary registers for other values, and load the base memory address of...

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