Question

Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0....

Compiling C Programs into MIPS Assembly and Machine Code

sll $t1, $a1, 2

add $t1, $a0. $t1

lw $t0, 0($t1)

lw $t2, 4($t1)

sw $t2, 0($t1)

sw $t0, 4($t1)

1. From the assembly code, what machine code might a MIPS assembler produce?

2. What does this program do? Write the C code for this assembly program.

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

Answer 1:

Machine code for the given assembly code:

0x00054880 0x00094820 0x8d280000 0x8d2a0004 0xad2a0000 0xad280004

Explanation:

Line 1: 0x00000000:0x00054880 [sll $t1 $a1 2 => R(op:0(sll) rs:0(0) rt:5(a1) rd:9(t1) sh:2 func:0)] Line 2: 0x00000004:0x00094820 [add $t1 $a0. $t1 => R(op:0(add) rs:a0.(a0.) rt:9(t1) rd:9(t1) sh:0 func:32)] Line 3: 0x00000008:0x8d280000 [lw $t0 0($t1) => I(op:35(lw) rs:9(t1) rt:8(t0) immed:0x00000000)] Line 4: 0x0000000c:0x8d2a0004 [lw $t2 4($t1) => I(op:35(lw) rs:9(t1) rt:10(t2) immed:0x00000004)] Line 5: 0x00000010:0xad2a0000 [sw $t2 0($t1) => I(op:43(sw) rs:9(t1) rt:10(t2) immed:0x00000000)] Line 6: 0x00000014:0xad280004 [sw $t0 4($t1) => I(op:43(sw) rs:9(t1) rt:8(t0) immed:0x00000004)]

Answer 2:

Given code is doing swapping of array elements.

C code for this assembly program:

temp = v[k];

v[k] = v[k+1];

v[k+1] = temp;

Explanation:

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0....
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
  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • Question 4) (12 Marks) This question is based on the MIPS assembly code shown below. data...

    Question 4) (12 Marks) This question is based on the MIPS assembly code shown below. data the Array: space 160 main: li $t6, 1 li $17, 4. sw $17, the Array($0) sw $17, theArray($17) li $t0, 8 loop: addi $t3, $t0, -8 addi $t4, $t0, -4 lw 1, the Array($t3) lw $12, the Array(St4) add $15, $t1, $t2 sw $15, theArray($to) addi $t0, $t0, 4 blt $t0, 160, loop jr Sra. Question 4 Assembly code a) what is the contents...

  • I AM POSTING MY QUESTION 3RD TIME . FIRST TWO TIMES I DIDNOT GET THE PROPER...

    I AM POSTING MY QUESTION 3RD TIME . FIRST TWO TIMES I DIDNOT GET THE PROPER ANSWER. PLEASE DO ALL STEPS BY LABELING THE EACH STEP. THIS IS THE ASSIGNMENT IN WHICH THE EACH STEP SHOULD BE LABEL . I MEAN EVERY THING SHOULD BE WRITTEN WHAT WE HAVE DONE IN OUR PROGRAM THIS IS THE REQUIREMENT OF TEACHER , PLEASE DO IT PROPERLY   1) MIPS to C. Assume that the variables f, g, h, i, and j are assigned...

  • Please answer the following questions involving MIPS assembly code: A) For the C statement below, what...

    Please answer the following questions involving MIPS assembly code: A) For the C statement below, what is the corresponding MIPS assembly code? Assume f, g are stored in S1 and S2. f = g + (-f -5) B) For the C statement below, what is the corresponding MIPS assembly code? Assume i and j are assigned in registers S1 and S2 respectively and base of address of arrays A and B are in registers S6 and S7. B[8] = A[i...

  • The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of...

    The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of using stack for storing/protecting registers. What is the mistake and how should it be fixed? Correct the corresponding lines in the code. For the corrected code, sketch the stack frame contents at the time when the instruction ‘move $s1, $a1’ is being executed. f:   addi $sp, $sp, 12 sw   $ra, 8($sp) sw   $s1, 4($sp) sw   $s0, 0($sp) move $s0, $a0 move $s1, $a1              #...

  • The task will be to write a program in assembler to enter a number and calculate...

    The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...

  • 1.Please use 5-stage pipeline to describe following MIPS assembly code in non-forwarding pipeline. lw         $s0,      0($t0)...

    1.Please use 5-stage pipeline to describe following MIPS assembly code in non-forwarding pipeline. lw         $s0,      0($t0) add        $s1,      $s0, $s0 mul       $s2,      $s1, $s0 . 2.Please use 5-stage pipeline to describe following MIPS assembly code in forwarding pipeline. lw         $s0,      0($t0) add        $s1,      $s0, $s0 mul       $s2,      $s1, $s0 sw         $s2,      4($t0)

  • Consider the following MIPS machine code.          bne $0, $0, 2          addi $t0, $0, 5          addi $t1,...

    Consider the following MIPS machine code.          bne $0, $0, 2          addi $t0, $0, 5          addi $t1, $0, 10 What will be in $t0 and $t1 after the above program is executed? a.       $t0 = 5, $t1 is unknown because 3rd statement will not be executed b.      $t1 = 10, $t0 is unknown because 2nd statement will not be executed c.       $t0 = 5, $t1 = 10 d.      $t0 = 0, $t1 = 0

  • This problem is adapted from an earlier edition of P&H. Consider the following code used to...

    This problem is adapted from an earlier edition of P&H. Consider the following code used to implement the instruction: foo $s0,$s1,$s2 mask: .word 0xFFFFF83F start: la $t0,mask lw $t0,0($t0) la $s0,shftr lw $s0,0($s0) and $s0,$s0,$t0 andi $s2,$s2,0x1f sll $s2,$s2,6 or $s0,$s0,$s2 la $t5,shftr sw $s0,0($t5) shftr: sll $s0,$s1,0 Add meaningful comments to the code. Please explain each line and write a paragraph describing how it works. Why do you suppose that writing “self-modifying code” such as this is a bad...

  • MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First...

    MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First ask the user how many elements of his/her array. 2) Then, read the integer array elements as input from the User. 3) Then, print out the array before the sorting 4) Apply Bubble sort algorithm on your array 5) Print out the array after the sorting 6) Print some welcome text to th user 7) Add comments to your code to describe how is...

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