Question

1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_

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

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You.


code snippet

mips01.asm 1 لا لا 3 4 main: li $a0,5 #load all with 5 li $ al, 10 #load al with 5 li $ a2,15 #load a 2 with 5 li $ a3,20 #lo

code

main:
li $a0,5 #load a0 with 5
li $a1,10 #load a1 with 5
li $a2,15 #load a2 with 5
li $a3,20 #load a3 with 5

jal leaf_example


li $v0,10 #terminate
syscall

leaf_example:
add $sp,$sp,-4
sw $s0,($sp) #save s0 to stack
add $t0,$a0,$a1 #get g+h
add $t1,$a2,$a3 #get i + j
sub $s0,$t0,$t1 #get (g+h)-(i+j)
move $v0,$s0 #move result to v0
lw $s0,($sp) #load data back to s0
add $sp,$sp,4
jr $ra

Add a comment
Know the answer?
Add Answer to:
1. [2 points] Write a MIPS assembly language program of the following C function and 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
  • 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

  • 6. [5 points] Translate the following c code to MIPS assembly code. f = g -...

    6. [5 points] Translate the following c code to MIPS assembly code. f = g - A(B[h]] The value of A, B, g, and h are in registers $a0, $al, $a2, and Sa3, respectively. The value of f should be stored in the register $v0.

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

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls...

    Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls multiply. You are also given the argument registers to be used. /* C-program */ int multiply (int number, int times) { int f; f = number * times return f; } # MIPS PROGRAM # assumes we have called the program leaf_example # $a0=number, $a1=times, $s0=f main: $addi $a0,$zero,3 $addi $a1,$zero,2 jal multiply # place the address into $ra j EXIT2 EXIT2: j OS...

  • Problem 2 Points (40) The following problems deal with translating from C to MIPS. Assume that...

    Problem 2 Points (40) The following problems deal with translating from C to MIPS. Assume that the variables g, h, j, and j are assigned to registers Ss0, Ss1, Ss2, Ss3, and Ss4, respectively. Assume that the base address of the arrays A and B are in registers Ss6 and Ss7 respectively 1. Provide the MIPS assembly code for the above C statements. Use a minimal number of MIPS assembly instructions 2. For the C statements above, how many MIPS...

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

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

    For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables i andj are assigned to registers $50 and $s1, respectively and the base address of the arrays A and B are in registers $s6 and $57, respectively. B[i] = A[B[j]+12];

  • Translate the following C code into a procedure in MIPS. Assume the two arguments are passed...

    Translate the following C code into a procedure in MIPS. Assume the two arguments are passed in registers $a0 and $a1. You are not required to preserve the values of registers $a0 and Şa1 1. [By the way-this is a basic implementation of the forward "predict" step of the 1-D Haar Lifting Transform, a kind of Discrete Wavelet Transform. The real version would use doubles, not ints.] void haarpredict (int vector[], int N) int half = N >> 1; int...

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