Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The attached skeleton code copies the content of one string to another. The strcpy procedure is the one we learnt in the class. It copies

The attached skeleton code copies the content of one string to another. The strcpy procedure is the one we learnt in the class. It copies the content of y string to x string. The program will input the y string, calculate its length, and copy the content of x string to y string. The program will show the length of the y string and the content of x string after calling the procedure strcpy. Your task is to complete the given skeleton program. You need to add one or more lines of code to accomplish tasks mentioned in the comments of this format: ### Comment ###. Add the lines of code after each of these comments to complete the program. Do not change/delete the existing code and/or existing comments.

 .data x_string: .space 40 y_string: .space 40 in_prompt: .asciiz "Input the y string (max 40 characters) and then press enter: " length_message: .asciiz "The length of the string is: " out_message: .asciiz " This is the content of x string after copying: " .text main: ### Print the input prompt### ### Read y string from the user using syscall ### ### Calcualte length of y string.### ### You have use a loop. Count the total no of cahracters until you find 0 in the string that incdicates the null terminator### ### Note, you need to use lbu for loading a Byte. ### ### Also, to access the next character in memory, increment the Byte number by 1 unlike array of words where you incremented by 4### ### Output the message for showing length ### ### Output the length of the string. Before printing, subtract 1 from the length as we do not want to count the newline character.### ### load the base addresses of the strings to a0 and a1 for the procedure call. a0 for x and a1 for y### jal strcpy ### Output the message for showing the x string ### ### Output x string### j exit #strcpy contains the code for copying y_string to x_string. #Base addresses of x_string and y_string are in $a0 and $a1 respectively strcpy: addi $sp, $sp, -4 # adjust stack for 1 item sw $s0, 0($sp) # save $s0 add $s0, $zero, $zero # i = 0 L1: add $t1, $s0, $a1 # addr of y[i] in $t1 lbu $t2, 0($t1) # $t2 = y[i] add $t3, $s0, $a0 # addr of x[i] in $t3 sb $t2, 0($t3) # x[i] = y[i] beq $t2, $zero, L2 # exit loop if y[i] == 0 addi $s0, $s0, 1 # i = i + 1 j L1 # next iteration of loop L2: lw $s0, 0($sp) # restore saved $s0 addi $sp, $sp, 4 # pop 1 item from stack jr $ra exit: li $v0, 10 syscall 

Example of output

image text in transcribed

Input the y string (max 40 characters) and then press enter: Hello The length of the string is: 5 This is the content of x string after copying: Hello -- program is finished running

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Describe why intercultural communication is a necessity

Answered: 1 week ago

Question

What were the reasons for your conversion or resistance?

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago