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
  • 2.4 For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the...

    2.4 For the MIPS assembly instructions below, what is the corresponding C statement? 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. sll $t0, $s0, 2               # $t0 = f * 4 add $t0, $s6, $t0         # $t0 = &A[f] sll $t1, $s1, 2               # $t1 =...

  • 1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw        &

    1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw          $t0, 0($a0)         #load the first array value into $t0 addi      $t1, $0, 1            #intialize the counter to one loop:                   beq       $t1, $a1, exit     #exit if we reach the end of the array addi      $a0, $a0, 4         #increment the pointer by one word addi      $t1, $t1, 1          #increment the loop counter lw          $t2, 0($a0)         #store the next array value into $t2 slt          $t3, $t0, $t2       beq      ...

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

  • Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...

    Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What is the address of label num3? _______________________________ Write the common syscall code to print string for the blank marked as #Question 2 _________________________________ Write proper comments for the lines marked as #Question 3 ________________________________________________________ Write the machine code for the line marked as #Question 4 in both binary and hex. Binary:_______________________________________ Hex:___________________ Write the machine code for the line marked as #Question 5 in...

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

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

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