Question

$s 10) if $si and $$2 are to be saved on the stack which of the following would accomplish the (10Pts) task? A) addi sp, sp, 8 sw $s1, 0($sp) sw $s2, 4($sp) B) addi sp, sp, 8 lw $s1, 8($sp) lw $s2, 4($sp) addi sp, sp, -8 C) sw $s1, 0($sp) sw $s2, 4(Ssp) D) addi sp, sp, -8 lw $s1, 8($sp) lw $s2, 4($sp) 11) What instruction would be used to call a procedure called square? (5Pts) 12) Where does a procedure return to in the main Program after a jr call? (5Pts)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C) is the answer for question 10. As, to store on the stack, first the stack pointer needs to be decreased. This is because stack grows downwards. Then, the two registers should be stored on the top, which is offset by 0 and then 4 bytes.

11) The final instruction would be "jr square", where square is the label for the procedure. Note that the arguments will need to stored properly before calling it.

12) The procedure returns to the address stored in $ra (called the return address register appropriately). This is stored on the stack when calling a procedure.

Comment in case of any doubts.

Add a comment
Know the answer?
Add Answer to:
$s 10) if $si and $$2 are to be saved on the stack which of 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
  • can someone explain how you get the answer to this question? 1. Based on the following code segment what values are in the runtime stack immediately after the fourth time the instruction labeled...

    can someone explain how you get the answer to this question? 1. Based on the following code segment what values are in the runtime stack immediately after the fourth time the instruction labeled Rec is executed .text li Sa0, 7 jai Fact #assume the address of this instruction is 2000 fother code not shown Fact: addi Ssp, Ssp, -8 sw Sra, 4(Ssp) sw Sa0, 0(Ssp) slti St0, Sa0, 1 beq St0, Szero, Rec li SvO, 1 addi $sp, Ssp, 8...

  • 2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp,...

    2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp, -4 addi Sa0, $0, 2 sw $a0, 4(Ss1) addi Sal, $0, 3 sw Sal, 8(Ss1) jal dofsum sw SvO, 16(8s1) lw Sra, O(Ssp) addi Ssp, Ssp, 4 jr Sra dofsum: jal sum jr Sra sum: add SvO, Sa0, Sal jr Sra Draw the snapshot of the stack before, during, and after dofsum) function call. As- sume SSP, 0x45fff00 before dofsum() function call.

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

  • ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra,...

    ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra, 4($sp) # save the return address on stack beqz $a0, terminate # test for termination subu $sp, $sp, 4 # do not terminate yet sw $a0, 4($sp) # save the parameter sub $a0, $a0, 1 # will call with a smaller argument jal Factorial # after the termination condition is reached these lines # will be executed lw $t0, 4($sp) # the argument I...

  • Write a MIPSzy subroutine, power, that accepts 2 arguments x and y and computes x^y ....

    Write a MIPSzy subroutine, power, that accepts 2 arguments x and y and computes x^y . You can assume that x and y are both larger than 0. The main program passes the two parameters and receives the return value through the program stack. addi $t0, $zero, 5100 top: lw $t1, 0($t0) beq $t1, $zero, done addi $sp, $sp, -4 sw $t1, 0($sp) addi $t2, $zero,4 addi $sp, $sp, -4 sw $t2, 0($sp) addi $sp, $sp, -4 jal power lw...

  • .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a...

    .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a0, $v0 jal factorial # jump factorial and save position to $ra move $t0, $v0 # $t0 = $v0 # show prompt li $v0, 4 la $a0, result syscall # print the result li $v0, 1 # system call #1 - print int move $a0,...

  • QT Spim question. Program and answer already given please explaine it. Please explain the reason why...

    QT Spim question. Program and answer already given please explaine it. Please explain the reason why each instruction was used throughout the program step by step given the prompt, what is its purpose to achive the goal asked in the prompt, why is written in that order. Please not just write to the side what each instruction means in words like load $t0 to $t1. I want to understand the program thoroughly. Thanks in advance Previous information needed to solve...

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

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

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