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]
2 years 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]2 years 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
There are many different types of hardware devices, different manufacturers, and countless configuration possibilities. Explain
erik [133]

Because, they are all required to configure to it to be recognized by an operating system.

Explanation:

It is the Operating System Software that instructs the hardware and puts them together to work well. When the manufacturer does not configure the device to be recognized by an operating system, then it will not work with other components.

Example.

If an Apple machine's sound card is being put in an HP machine which uses Microsoft designed operating system, won't work due to the operating system that the sound card has been designed for.

6 0
2 years ago
In this image, which feature did we most likely use to quickly change the background, fonts, and layout?
MAVERICK [17]

Answer: themes

Explanation:

Took the test

3 0
1 year ago
Menus are attached to windows by calling the _____ method.
Kruka [31]

Answer: setJMenubar

Explanation:Menus that are component of the Menu bar that display the options and tools for any function that can be performed in the system have the connection with the window in the field of java through the command of the setJMenubar. It is the command which is given to execute to bring the menu to the particular frame and get it attached according to the JFrame. Therefore, the correct option is setJMenubar.

6 0
2 years ago
System design is the determination of the overall system architecture-consisting of a set of physical processing components, ___
Alenkinab [10]

Answer:

C) Hardware, Software, People

Explanation:

System design is the determination of the overall system architecture-consisting of a set of physical processing components, Hardware, Software, People and the communication among them-that will satisfy the system’s essential requirements.

5 0
2 years ago
Read 2 more answers
6. Write pseudo code that will perform the following. a) Read in 5 separate numbers. b) Calculate the average of the five number
Alex

Answer:

Pseudo CODE

a)

n= Input “Enter 5 integer value”

b)

sum=0.0

For loop with i ranging from 0 - 5

Inside loop sum=n[i]+sum

Outside loop avg= sum/5

Print avg

c)

small=n[0] # assume the first number in the list is smallest

large= n[0] # assume the first number in the list is largest

For loop with i ranging from 0 - 5

Inside loop if n[i]<small #if any another number is smaller than small(variable)

Inside if Then small=n[i]

Inside loop if n[i]>large # if any another number is larger than large(variable)

Inside if then large=n[i]

Print small

Print large

d)

print avg

print small

print large

8 0
2 years ago
Other questions:
  • Elaine is upset with her group members because she wanted to lead the group but is not allowed to. She found that other group me
    9·2 answers
  • In a spreadsheet, the instructions for carrying out calculations are called __________. recalculations formulas templates macros
    13·1 answer
  • Classify the given items as belonging to the public domain or protected by copyright law.
    6·2 answers
  • 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
  • Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only
    9·2 answers
  • Write the definition of a function named averager that receives a double parameter and return-- as a double -- the average value
    12·1 answer
  • Write a loop that continually asks the user what pets the user has, until the user enters "rock", in which case the loop ends. I
    12·1 answer
  • A bank in your town updates its customers’ accounts at the end of each month. The bank offers two types of accounts: savings and
    8·1 answer
  • Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences
    7·1 answer
  • An online retailer is looking to implement an enterprise platform. Which component of the enterprise platform will help the comp
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!