Question

In: Computer Science

In this assignment we will be working with both text strings and a user input integer...

In this assignment we will be working with both text strings and a user input integer array from the data segment. The goal of the assignment is to have the user choose the number of items that they want to have in an array (we will keep it a small number for now, 1-10) and then enter those values which we will store into our array. We then want to allow them to search for a specific item in the list of number that they just entered and report if the number was found or not. Requirements:

• Name your program P02LastNameFirstName.asm

• You must make use of the data segment in order to both have strings to prompt the user and to have a location to store the values the user inputs.

• String prompts and information about the program must be given to the user in a well formatted and logical fashion so that someone using the program with no knowledge about it would understand what is happening.

• The user must be allowed to choose the number of items they are going to input, though we will limit it to a smaller number (1-10).

• The user can then enter their integers, which must be stored in the array defined in the data segment.

• You will then prompt the user for an integer to search for and then search through the input array to see if it is present. • If it is, report success. If it is not found, report failure.

Hints: • Remember that the data segment holds the larger pieces of data and the text segment has the instructions that will be run. • You can define an area for more data than you use. • Using “.align #” in the data segment can help if your array is not aligned on memory boundaries (an error you may encounter). The # refers to the boundary you want to align on, check the tooltip in MARS for more information. The value 2 is the likely choice. • Keep in mind that since we are working with integers, that we will need to move through our array with their size in mind.

Solutions

Expert Solution

SOULTION:

Program

#Data declaration part
.data
#In formation display about program
info: .asciiz "User Manual:\n This program allows user to enter number of items in an array of integers.\n Then allow to enter integers of that count into array.\n Maximum items are 1-10.\n The user can search for the items\n\n
#Array to store items
intArr: .word 0 0 0 0 0 0 0 0 0 0
#Prompt for item
prompt1: .asciiz "Enter the item count(1-10): "
#Get integers
prompt2: .asciiz "\nEnter integers: "
#Search prompt
prompt3: .asciiz "\nEnter number to search: "
#Outputs
out1: .asciiz " Found in array!!!\n"
out2: .asciiz " Not Found in array!!!\n"
#Error messages
err1: .asciiz "Item count must be 1-10!!!Re-enter please...\n\n"
#Program starts here
.globl main
.text
main:
#display user manual
la $a0,info
li $v0,4
syscall
#Get address of the array
la $s0,intArr
#Call function to get number of items going to enter in the array
jal getCount
#Store count in s1
move $s1,$v0
#Get items into array
#Pass arguments to function
move $a0,$s0
move $a1,$s1
jal inputArray
#Search function call
move $a0,$s0
move $a1,$s1
jal searchArray
#End of the program
li $v0,10
syscall

#Implementation of function to get number of items going to enter in the array
getCount:
#Display prompt
la $a0,prompt1
li $v0,4
syscall
#Read count
li $v0,5
syscall
#Check error conditions
blt $v0,1,error1
bgt $v0,10,error1
#Otherwise return count to main
jr $ra
#Display error
error1:
la $a0,err1
li $v0,4
syscall
j getCount

#Implementation of inputting array integers
inputArray:
#Array address in to
move $t0,$a0
#Inputting loop
loopInput:
#Condition
beq $a1,0,retMain
#Display prompt
la $a0,prompt2
li $v0,4
syscall
#Read value
li $v0,5
syscall
#Store into array
sw $v0,($t0)
#increment address
addi $t0,$t0,4
#Decrement count
addi $a1,$a1,-1
#repeat
j loopInput
#Return to main
retMain:
jr $ra

#Implementation of search function
searchArray:
#Array address in to
move $t0,$a0
#Get element to search
la $a0,prompt3
li $v0,4
syscall
#read number
li $v0,5
syscall
#Inputting loop
loopInput1:
#Condition
beq $a1,0,failure
#Get array element
lw $t1,($t0)
#compare
beq $t1,$v0,success
#increment address
addi $t0,$t0,4
#Decrement count
addi $a1,$a1,-1
#repeat
j loopInput1
#Success message
success:
move $a0,$v0
li $v0,1
syscall
la $a0,out1
li $v0,4
syscall
jr $ra
#Failure message
failure:
move $a0,$v0
li $v0,1
syscall
la $a0,out2
li $v0,4
syscall
jr $ra

Output

User Manual: This program allows user to enter number of items in an array of integers.
Then allow to enter integers of that count into array.
Maximum items are 1-10.
The user can search for the items

Enter the item count(1-10): 0

Item count must be 1-10!!!Re-enter please...
Enter the item count(1-10): 11

Item count must be 1-10!!!Re-enter please...
Enter the item count(1-10):

User Manual:
This program allows user to enter number of items in an array of integers.
Then allow to enter integers of that count into array.
Maximum items are 1-10.
The user can search for the items

Enter the item count(1-10): 11
Item count must be 1-10!!!Re-enter please...

Enter the item count(1-10): 0
Item count must be 1-10!!!Re-enter please...

Enter the item count(1-10): 4

Enter integers: 25

Enter integers: 14

Enter integers: 36

Enter integers: 10

Enter number to search: 10
10 Found in array!!!

-- program is finished running --

OUTPUT:

THANKU YOU


Related Solutions

Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
In Java:Implement a program that repeatedly asks the user to input apositive integer and...
In Java:Implement a program that repeatedly asks the user to input a positive integer and outputs the factorial of that input integer. Do not use recursion, solution should use stack.
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it...
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it is a positive integer >= 0 3.Allocate (dynamically) an array big enough for the data. 4.Load the array with random numbers ranging in value from1 to 100 5.Display the elements of the array (unsorted) 6.Display the elements of the array (sorted) 7. Display the average 8.Display the median 9.Display the mode, if none, display appropriate message #include <iostream> #include <stdlib.h> /* srand, rand */...
write both non-recursive and recursive functions that take the strings from the user and display strings...
write both non-recursive and recursive functions that take the strings from the user and display strings in backwards in python
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and a negative integer validates the inputs using a loop and then calls the METHOD from Question 3 and prints the result. The MAIN should have two variables (appropriately typed), get the input from the user and store them in the variables after validating them, then call the method from question 3 (sending parameters, if necessary) and print the returned value with an appropriate descriptive...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT