answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NikAS [45]
1 year ago
10

For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of instructions to save/restore values on the

stack and update the stack pointer. Assume that procA and procB were written independently by two different programmers who are following the MIPS guidelines for caller-saved and callee-saved registers. In other words, the two programmers agree on the input arguments and return value of procB, but they can't see the code written by the other person.(50 points)
procA:
$s0 = ...
$s1 = ...
$s2 = ...
$t0 = ...
$t1 = ...
$t2 = ...
X
$a0 = ...
$a1 = ...
jal procB
Y
... = $s1
... = $t0
... = $t1
... = $a0
jr $ra

procB:
P
... = $a0
... = $a1
$s2 = ...
$t0 = ...
Q
jr $ra
Computers and Technology
1 answer:
Dimas [21]1 year ago
8 0

Answer:

Explanation:

Let us first consider the procedure procA; the caller in the example given.

  Some results: $s0,$s1,$s2, $t0,$t1 and $t2 are being stored by procA. Out of these registers, few registers are accessing by procA after a call to procB. But, procB might over-write these registers.

       Thus, procA need to save some registers into stack first before calling procB, .

      only $s1,$t0 and $t1 are being used after return from procB in the given example,

       Caller saves and restores only values in $t0-$t9, according to MIPS guidelines for caller-saved and callee-saved registers, .

       Thus, procA needs to save only $t0 and $t1.

    jal instruction overwrites the register $ra by writing the address, to which the control should jump back, after completing the instructions of procB, when procB is called,.

       Therefore, procA also need to save $ra into stack.

 ProcA is writing new values into $a0,$a2, procA must save $a0 and $a1 first before calling procB, .

     In the given example, after return from procB, only $a0 is being used. It is therefore enough to save $a0.

   Also, procA needs to save frame pointer, which points the start of the stack space for each procedure.

       Generally, as soon as the procedure begins, frame pointer is set to the current value of the stack pointer,.

Let us consider the procedure procB; the callee in the given example.

 The callee is responsible for saving values in $s0-$s7 and restoring them before returning to caller, this is according to MIPS guidelines for caller-saved and callee-saved registers,

   procB is expected to over-write the registers $s2 and $t0. Nonetheless, in the first two lines, procB might over-write the registers $s0 and $s1.

   Thus, procB is responsible for saving and restoring $s0,$s1 and $s2.

X:

We need to create space for 5 values on the stack since procA needs to save $a0,$ra,$t0,$t1 and $fp(frame pointer), . Each value(word) takes 4 bytes.

$sp = $sp – 20 # on the stack, create space for 5 values

sw $a0, 16($sp) # store the result in $a0 into the memory address

               # indicated by $sp+20

sw $ra, 12($sp) # save the second value on stack

sw $t0, 8($sp) # save the third value on stack

sw $t1, 4($sp) # save the fourth value on stack

sw $fp, 0($sp) #  To the stack pointer, save the frame pointer

$fp = $sp      #  To the stack pointer, set the frame pointer

Y:

lw $fp, 0($sp) #  from stack, start restoring values

lw $t1, 4($sp)

lw $t0, 8($sp)

lw $ra, 12($sp)

lw $a0, 16($sp)

$sp = $sp + 20 # decrease the size of the stack

P:

$sp = $sp – 12 #  for three values, create space on the stack

sw $s0, 0($sp) # save the value in $s0

sw $s1, 0($sp) # save the value in $s1

sw $s2, 0($sp) # save the value in $s2

Q:

lw $s0, 0($sp) #  from the stack, restore the value of $s0

lw $s1, 0($sp) #  from the stack, restore the value of $s1

lw $s2, 0($sp) #  from the stack, restore the value of $s2

$sp = $sp + 12 # decrease the stack size

You might be interested in
While adding voices to an animation, what kind of room should you choose?
MrRissso [65]

Answer:

A. A quiet room

Explanation:

Because if you open the windows the will be noise

a huge room will echoe

a room with air conditioning will make noise

7 0
2 years ago
Rene has secured her wireless network. However, she is worried about securing her router against newfound vulnerabilities. Which
Fynjy0 [20]
It is C I have a lot of experience with computers and technology
4 0
1 year ago
Constantine forms the following hypothesis. Let n be any non-negative number that meets the following condition: when n is divid
notka56 [123]

Answer:

n=5

Explanation:

if n= 5

i.     n/5=5/5=1  so it divides completely the remainder is 0

ii.  97 - 6(5) = 97 - 30 = 67,   67 is a prime number.

8 0
2 years ago
When this program is compiled and executed on an x86-64 Linux system, it prints the string 0x48\n and terminates normally, even
Alexxandr [17]

Answer:

I get 0x55 and this the linking address of the main function.

use this function to see changes:

/* bar6.c */

#include <stdio.h>

char main1;

void p2()

{

printf("0x%X\n", main1);

}

Output is probably 0x0

you can use your original bar6.c with updaated foo.c

char main;

int main() // error because main is already declared

{

  p2();

   //printf("Main address is 0x%x\n",main);

  return 0;

}

Will give u an error

again

int main()

{

  char ch = main;

  p2(); //some value

  printf("Main address is 0x%x\n",main); //some 8 digit number not what printed in p2()

  printf("Char value is 0x%x\n",ch); //last two digit of previous line output

  return 0;

}

So the pain in P2() gets the linking address of the main function and it is different from address of the function main.

Now char main (uninitialized) in another compilation unit fools the compiler by memory-mapping a function pointer on a char directly, without any conversion: that's undefined behavior. Try char main=12; you'll get a multiply defined symbol main...

Explanation:

5 0
1 year ago
Get user input as a boolean and store it in the variable tallEnough. Also, get user input as a boolean and store it in the varia
frozen [14]

Answer:

I will code in JAVA.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 

boolean tallEnough;

boolean oldEnough;

Scanner input = new Scanner(System.in);

tallEnough = input.nextBoolean();<em> //wait the input for tallEnough</em>

oldEnough = input.nextBoolean(); <em>//wait the input for OldEnough</em>

   if(tallEnough && oldEnough){

   System.out.print(true);

   } else {

   System.out.print(false);

   }

}

}

Explanation:

First, to accept user inputs you have to import the class Scanner. Then declare both variables before allowing the user to set input values for both boolean variables.

In the if-else statement checks if both variables are true, then prints true. Another case prints always false.

8 0
1 year ago
Other questions:
  • Allows you to manually add an entry to the arp cache that resolves the ip address inetaddr to the physical address etheraddr. wh
    13·1 answer
  • Which key retains its uniqueness even after you remove some of the fields?
    14·1 answer
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
    10·1 answer
  • In a system containing CPU 1 and Disk Drive A, the system is instructed to access Track 1, Track 9, Track 1, and then Track 9 of
    12·1 answer
  • Which would be the most efficient way to store files on your computer?
    13·2 answers
  • Chris accidentally steps on another student’s foot in the hallway. He apologizes, but the other student does not want to hear it
    13·2 answers
  • Modify the closest pair of points algorithm so that the separating line L now separates the first n/4 points (sorted according t
    14·1 answer
  • In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the mont
    14·1 answer
  • Which of the following could NOT be represented by a boolean variable?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!