Question: Please explain in detail step by step Write a MIPS program that contains a function called generate _ echo _ string. The function should implement
Please explain in detail step by step
Write a MIPS program that contains a function called generateechostring. The function should implement the following C code:
These should be global variables in your program's
data section.
char prefix "You typed: ;
char prompt "Enter a string: ;
This function accepts the address of a string that currently
has no contents as an argument. The function will ask the user
to type a string. The function will put the prefix string declared
above at the beginning of stringtomodify, followed by whatever
the user typed.
So if the user types Hi there!", this function should place the
following characters, in order, starting at the address specified
by stringtomodify:
You typed: Hi there!
void generateechostringchar stringtomodify, int maxbytes
Put a NULL byte at the end of stringtomodify, just to be
safe.
stringtomodifymaxbytes ;
int prefixlength strlenprefix;
strncpystringtomodify, prefix, maxbytes ;
It's possible that we've already used up all our bytes.
if prefixlength maxbytes
return;
The address where you start writing the text entered
by the user.
char startingpoint stringtomodify prefixlength;
Now, let the user type, and copy as much as you can to
stringtomodify.
InputConsoleStringprompt startingpoint, maxbytes prefixlength;
You should also write a main function to test your function. When you submit, the tests will replace your main function, so what you include in it is up to you.
Once again, note that you will need to include util.s at the bottom of your program using a include directive, like this:
include utils
This assumes that util.s can be found in the same directory as your program. You should not submit util.s along with your program just submit your program file.
strcpy:
move $v$a
# int InputConsoleString char message char buf, int max
# message is a message to be displayed
# buf is a pointer to a character buffer at least of length max.
#
# The return value is the number of characters stored in buf,
# not counting the null byte thus equivalent to strlenbuf
#
# buf is always nullterminated and the newline does not appear in buf.
# If the user entered too much data, the extra data is lost.
#
text
globl InputConsoleString
InputConsoleString:
# int InputConsoleString char message char buf, int max
# leaf function
# home arguments
sw $a$sp
sw $a$sp
sw $a$sp
li $t
sb $t$a
# Display prompt
li $v
syscall
# Retrieve string
lw $a$sp
lw $a$sp
li $v
syscall
#
# look for newline in buffer and store a nul byte on it
#
lw $t$sp
# unsigned strlenconst char s
# returns the length of s not including the null byte
# s is assumed to NOT be NULL
#
globl strlen
strlen:
# a has address of string
li $v
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
