hw4_chartype
.docx
keyboard_arrow_up
School
University of Massachusetts, Lowell *
*We aren’t endorsed by this school
Course
2030
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
4
Uploaded by BarristerRoseMouse35
COMP.2030
HW 4: CharType
Due: 10/10 (Tue)
Write a MIPS program which repeatedly reads a line of characters from the keyboard,
determines the “type” of each character in that line, and then prints the sequence of character types
matching the input string. The different character types are:
Characters
Type
Comment
0
1
.. 9
1
Digits
A
B
.. Z
a
b
.. z
2
Letters
*
+
-
/
3
Operators
.
(
)
,
:
$
4
Delimiters
#
5
End of the Line
6
blank (0x20)
Your program should repeat the following operations in a loop:
(1)
read a line from the keyboard and save it in a buffer
inBuf
of 80 characters,
(2)
for each character in the input line, search the table
tabChar
for its type and save the
corresponding numeric type value in another buffer
outBuf
,
(3)
print the
outBuf
that was filled for this input line, and
(4)
repeat back at step 1
As an example, when the following is entered on the keyboard
THISLOOP:
LWU
R2, 3
#
the output printed by the program should be
222222224
222
2141
5
Note that each input line is required to terminate with a ‘#’ character as the end-of-the-line symbol.
The blank type of 6 for spaces can be left out when printing character types.
Approaches:
A rough structure of the program is as follows:
while (1) {
getline(inBuf);
int i = 0;
while (inBuf[i] != ‘#’) {
chType = search(inBuf[i]);
outBuf[i] = char(chType);
i++;
}
print outBuf;
clear inBuf;
clear outBuf;
}
1. Reading input lines
Two buffers need to be declared to save characters in an input line and to store output character types.
.data
inBuf:
.space
80
# input line
outBuf:
.space
80
# char types for the input line
prompt:
.asciiz
"Enter a new input line. \n”
An example of the
getline
procedure to read an input string is as follows:
.text
getline:
la
$a0, prompt
# Prompt to enter a new line
li
$v0, 4
# Command code to write to the
screen
syscall
la
$a0, inBuf
# Store the user input in inBuf
li
$a1, 80
# inBuf has space for 80 character
li
$v0, 8
# Command code to read a new line
syscall
jr
$ra
# Return
2. Character Search
A simple approach to finding a character type is to arrange all characters and their types into a
2D array. This makes future changes and updates to the character set a quick process. Use the MIPS table
tabChar
below and write either a linear or a binary search function to search for a character. Be careful
that a character from the input string is stored as one byte, whereas the search table below is organized
in units of words (4-bytes each). When you compare a letter from the input string to characters in
tabChar
, make it sure that you use
‘
lb
’
instruction to move only a byte out of the input string to one of
registers.
What to submit:
Name your .asm MIPS source code as your last name and submit the .asm file.
tabChar table:
.data
tabChar:
.word
0x09, 6
# tab
.word
0x0a, 6
# line feed
.word
0x0d, 6
# carraige return
.word
' ', 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
String - Practice Questions
Write a python program using strings to read input from the
user and count the character a.
Write a python program using strings to read two input and
convert the first input to lowercase and second input to
uppercase.
Write a python program using strings to read input from the
use and replace all the character a with z.
Write a python program using strings to read input from the
user and find the length of the string.
arrow_forward
Python problem
To decipher a code we must make a program that performs certain operations on the input string.
-If they find 3 equal letters in a row, you must replace them with the next letter in the alphabet.-If you only find 2 equal letters in a row, you must replace them with the previous letter in the alphabet.-The comma must be removed-The period should be left and a space added after it.-All other characters should be left as isNote that in this case after the "Z" is the "A", and therefore before the "A" is the "Z".
Given a string S, execute the operations described above, until no more can be executed. For example:
GHHGP, OOOMMZAAZ => GGGPPLZZZ => HELLO
EntryThe input will be a single line containing the string S. The string only includes uppercase letters of the English alphabet and special characters.
DepartureYou must print the resulting string in double quotes ".
Examples
Input Example 1
LLLENTTA, JDDD OBCCBUMMTO!Output Example 1
"HIDDEN MESSAGE!"
Input Example 2…
arrow_forward
Python problem
To decipher a code we must make a program that performs certain operations on the input string.
-If they find 3 equal letters in a row, you must replace them with the next letter in the alphabet.-If you only find 2 equal letters in a row, you must replace them with the previous letter in the alphabet.-The comma must be removed-The period should be left and a space added after it.-All other characters should be left as isNote that in this case after the "Z" is the "A", and therefore before the "A" is the "Z".
Given a string S, execute the operations described above, until no more can be executed. For example:
GHHGP, OOOMMZAAZ => GGGPPLZZZ => HELLO
EntryThe input will be a single line containing the string S. The string only includes uppercase letters of the English alphabet (Does not include Ñ) and special characters.
DepartureYou must print the resulting string in double quotes ".
Examples
Input Example 1
LLLENTTA, JDDD OBCCBUMMTO!Output Example 1
"HIDDEN…
arrow_forward
Dont use #include <bits/stdc++.h>use #include <iostream>
arrow_forward
Alert dont submit AI generated answer.
Please code in C language.
arrow_forward
Encoding Input-
Write a program to take input a string from user and encode the string according to rules given below.
Replace all digits in the string by (digit+5)%10
Replace all uppercase alphabets to lowercase alphabet.
Print the encoded string in output.
language- C++
arrow_forward
Under all code in check.
arrow_forward
(Python programming)
Write a program that incorporates an algorithm with a function that will check whether or not a string is in a valid password format with the following rules:
A password must have at least ten characters.A password consists of only letters, digits and symbol(s).A password must contain at least two digits.
A password must contain at least one uppercase letter
A password must contain at least one special symbol
Your program should continue to prompt until the user enters a valid password.
Regular expressions (regex) are not allowed!
arrow_forward
10. Exercise 9 - Strings (Assessed Exercise)
Important:
Do not attempt this exercise before completing Exercises 6, 7 and 8.
Think how to reuse the functions you created in Exercises 6, 7 and 8.
Design and Problem Solving: Create an algorithm for a program that reads a string with a
maximum length of N from the keyboard (N should be specified by the user). N should not be
more than 100.
The algorithm should then copy the characters from that input string into a second character
array (in the order of input). However, a character will be copied into the second array only if it is
a vowel (i.e., a, e, i, o, u). This second array should be allocated dynamically and its size will
depend on the number of characters that will be copied into it.
Murdoch
UNIVERSITY
Once copied, the algorithm should output the values stored in the second string.
The algorithm should then count and display the number of times each vowel appears in the
second array. Also, the algorithm should determine and output…
arrow_forward
use c++and #include <iostream> domain
arrow_forward
please quickly thanks !!
use Python
arrow_forward
Allowed language: C language The output should be the same with example and please code correctly. Pls do not copy from other questions
arrow_forward
Character Count
Code in C language
arrow_forward
Question m .In C programming Language
Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this line
arrow_forward
Questions:
Computer-Assisted Instruction) The use of computers in education is referred to as computer- assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as
How much is 6 times 7?
The student then inputs the answer. Next, the program checks the student’s answer. If it’s correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly.
PLEASE IN C++ LANGUAGE
arrow_forward
(1) Prompt the user for a string that contains two strings separated by a comma
• Examples of strings that can be accepted:
• Jill, Allen
• Jill, Allen
• Jill, Allen
Ex:
Enter input string:
Jill, Allen
(2) Print an error message if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input
contains a comma, then assume that the input also contains two strings
Ex:
Enter input string:
Jill Allen
Error: No comma in string.
Enter input strings
ming Fundamentals home > 9.11: LAB: Warm up: Parsing strings
Ex:
(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings.
Enter input string:
Jill, Allen
First word: Jill
Second word: Allen
(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit
Ex:
Enter input string:
Jill, Allen
First word: Jill
Second word: Allen
0
Enter input string:
Golden Monkey
,
First…
arrow_forward
TEST INPUT: I Love C Programming
Write a program to replace all the vowels with empty spaces in a sentence. For example- if your input
string is "Hello World!!", your output string should be "H II W rld!!" [The sentence must be stored in a
dynamically allocated memory.]
arrow_forward
Exercise 2(strcat_ba_test): Complete the following function, strcat_ba(a, b), so that given two strings a and b, it returns the concatenation of b followed by a(pay attention to the order in these instructions!)
Python programming
arrow_forward
Write a function that searches for a particular character in a string using the following header:
void search(string& s, char& key)
Write a test program that prompts the user to enter the string and a character and displays if the character is found.
arrow_forward
/*-
arrow_forward
String to integer ATOI (requires use of INT_MAX and INT_MIN):
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
The algorithm for myAtoi(string s) is as follows:
Read in and ignore any leading whitespace.
Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less…
arrow_forward
Use below input sample:
"texterretxet" is a palindromic string"
"dwayne" is not palindrome
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- String - Practice Questions Write a python program using strings to read input from the user and count the character a. Write a python program using strings to read two input and convert the first input to lowercase and second input to uppercase. Write a python program using strings to read input from the use and replace all the character a with z. Write a python program using strings to read input from the user and find the length of the string.arrow_forwardPython problem To decipher a code we must make a program that performs certain operations on the input string. -If they find 3 equal letters in a row, you must replace them with the next letter in the alphabet.-If you only find 2 equal letters in a row, you must replace them with the previous letter in the alphabet.-The comma must be removed-The period should be left and a space added after it.-All other characters should be left as isNote that in this case after the "Z" is the "A", and therefore before the "A" is the "Z". Given a string S, execute the operations described above, until no more can be executed. For example: GHHGP, OOOMMZAAZ => GGGPPLZZZ => HELLO EntryThe input will be a single line containing the string S. The string only includes uppercase letters of the English alphabet and special characters. DepartureYou must print the resulting string in double quotes ". Examples Input Example 1 LLLENTTA, JDDD OBCCBUMMTO!Output Example 1 "HIDDEN MESSAGE!" Input Example 2…arrow_forwardPython problem To decipher a code we must make a program that performs certain operations on the input string. -If they find 3 equal letters in a row, you must replace them with the next letter in the alphabet.-If you only find 2 equal letters in a row, you must replace them with the previous letter in the alphabet.-The comma must be removed-The period should be left and a space added after it.-All other characters should be left as isNote that in this case after the "Z" is the "A", and therefore before the "A" is the "Z". Given a string S, execute the operations described above, until no more can be executed. For example: GHHGP, OOOMMZAAZ => GGGPPLZZZ => HELLO EntryThe input will be a single line containing the string S. The string only includes uppercase letters of the English alphabet (Does not include Ñ) and special characters. DepartureYou must print the resulting string in double quotes ". Examples Input Example 1 LLLENTTA, JDDD OBCCBUMMTO!Output Example 1 "HIDDEN…arrow_forward
- Dont use #include <bits/stdc++.h>use #include <iostream>arrow_forwardAlert dont submit AI generated answer. Please code in C language.arrow_forwardEncoding Input- Write a program to take input a string from user and encode the string according to rules given below. Replace all digits in the string by (digit+5)%10 Replace all uppercase alphabets to lowercase alphabet. Print the encoded string in output. language- C++arrow_forward
- Under all code in check.arrow_forward(Python programming) Write a program that incorporates an algorithm with a function that will check whether or not a string is in a valid password format with the following rules: A password must have at least ten characters.A password consists of only letters, digits and symbol(s).A password must contain at least two digits. A password must contain at least one uppercase letter A password must contain at least one special symbol Your program should continue to prompt until the user enters a valid password. Regular expressions (regex) are not allowed!arrow_forward10. Exercise 9 - Strings (Assessed Exercise) Important: Do not attempt this exercise before completing Exercises 6, 7 and 8. Think how to reuse the functions you created in Exercises 6, 7 and 8. Design and Problem Solving: Create an algorithm for a program that reads a string with a maximum length of N from the keyboard (N should be specified by the user). N should not be more than 100. The algorithm should then copy the characters from that input string into a second character array (in the order of input). However, a character will be copied into the second array only if it is a vowel (i.e., a, e, i, o, u). This second array should be allocated dynamically and its size will depend on the number of characters that will be copied into it. Murdoch UNIVERSITY Once copied, the algorithm should output the values stored in the second string. The algorithm should then count and display the number of times each vowel appears in the second array. Also, the algorithm should determine and output…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education