3. What is the lowest value of the stack pointer (sp) during the program? 4. What registers are used for the arguments to subroutines and the return values?
3. What is the lowest value of the stack pointer (sp) during the program? 4. What registers are used for the arguments to subroutines and the return values?
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
please solve parts 3 and 4, note that this question is not a graded question, please don't reject it

Transcribed Image Text:Part 2.4: Example #3
1. What is the cycle count when the program
finishes?
2. How many new lines of instructions were added
(diff example_2.s example_3.s)?
3. What is the lowest value of the stack pointer (sp)
during the program?
4. What registers are used for the arguments to
subroutines and the return values?

Transcribed Image Text:.globl main
# Defines
.eqv PRINT_INT 1
.eqv PRINT_STR 4
.eqv EXIT_CODE 93
.data
input:
.word 6
output:
.word 0
result_str:
.asciz "!= "
.text
main:
lw a0, input
jal fact_func
la to, output
sw a0,0(t0)
exit:
lw a0, input
li a7, PRINT_INT
ecall
la a0, result_str
li a7, PRINT_STR
ecall
lw a0, output
li a7, PRINT_INT
ecall
li a0, 0
li a7, EXIT_CODE
ecall
ebreak
addi sp, sp, -16
SW SO, 0(sp)
SW S1,
4 (sp)
sw s2,
8(sp)
sw ra, 12 (sp)
mv s0, a0
li to, 1
ble s0, t0, done_fact
addi s1, s0, -1
li a0,1
li s2,1
blez s1,done_fact
addi s2, s2,1
mv a1, s2
jal mul_func
addi s1,s1,-1
j do_fact
lw s0, 0(sp)
lw s1, 4(sp)
lw $2, 8 (sp)
lw ra, 12(sp)
addi sp, sp, 16
ret
addi sp, sp, -12
sw s0, 0(sp)
sw s1, 4(sp)
sw ra, 8(sp)
mv s0, a0
mv s1, a1
mul a0, s0, s1
1w s0, 0(sp)
lw s1, 4(sp)
lw ra, 8(sp)
addi sp, sp, 12
ret
fact_func:
do_fact:
done_fact:
mul_func:
# The location for the input data
# allocates 4 byte set to 6
# The location for the output data
# allocates 4 byte set to 0
# The location for the result string data
# allocates 1 byte per chacter plus null character
# Label for start of program
#Load input Value
# Jump and link (save return address) to factorial function.
# Load output address to to
# Save output value to output memory location
# Load Input value into ao
# System call code for print_int code 1
# Make system call
# Put result_str address in a0
# System call code for print_str code 4
# Make system call
# Load output value into ao
# System call code for print_int code 1
# Make system call
# Exit (93) with code 0
# System call value
# Make system call
# Finish with breakpoint
# Make room to save values on the stack
#This function uses 3 callee save regs.
# This function is responsible for them
# Each register is 4 bytes
# The ra needs to be saved in case jal is used again
# Save the argument into so
# Loads the value 1 into a to
# If Input is 1 or less, then skip to end
# Put input-1 into s1
# Load 1 in a0 (caller saved/ argument)
# Load 1 in s2 (callee saved)
# If s1 is less than or equal to zero then jump to end
# Increment s2 by 1
#Move s2 into a1 (argument)
# Multiply subroutine, argument (a0,a1) return value (a0)
#decrement s1 counter
# jump to top of loop to do next factorial until s1 is 0
# Restore any callee saved regs used
# Each register is 4 bytes
#
# Retore correct return address
# Update stack pointer
# Jump to return address
# Make room to save values on the stack
# This function uses 2 callee save regs.
# This function is responsible for them
# Save the return address
# Save the arguments in callee save regs
#
# Multiply argument and output to a0
# Restore any callee saved regs used
# Each register is 4 bytes
# Restore return address
# Update stack pointer
# Jump to return address
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY