Question

In: Computer Science

write a MIPS program to ask user to input the number of elements of array

write a MIPS program to ask user to input the number of elements of array

Solutions

Expert Solution

Code:-----

.text
.globl __start

__start: la $s0, array # set $s0 to point array[0]
li $s1, 0 # $s1 = 0 (for counting the array elements)

loop1: li $v0, 4
la $a0, prompt
syscall # Print the prompt
li $v0, 5
syscall # Read an integer in $v0
lw $t0, endmark
beq $v0, $t0, exit # if $v0 = endmark then exit loop
sw $v0, 0($s0) # store $v0 into the current element
addi $s0, $s0, 4 # move to the next element
addi $s1, $s1, 1 # increment the counter
b loop1

exit: li $v0, 4
la $a0, res
syscall

add $a0, $0, $s1
li $v0, 1
syscall # Print the number of elements entered

li $v0, 4
la $a0, el
syscall

la $s0, array # set $s0 to point to array[0]

loop2: lw $a0, 0($s0) # $a0 = current element
li $v0, 1
syscall # Print $a0
li $v0, 4
la $a0, nl
syscall
add $s0, $s0, 4 # move to the next element
addi $s1, $s1, -1 # decrement element counter
bne $s1, $0, loop2

li $v0, 4
la $a0, bye # Print the end message
syscall
li $v0, 5
syscall # wait for Enter

li $v0, 10
syscall # end of program

.data
array: .word 0,0,0,0,0,0,0,0,0,0
prompt: .asciiz "Enter an integer (-999 for exit): "
endmark: .word -999
res: .asciiz "You have entered "
el: .asciiz " numbers:\n"
bye: .asciiz "Press enter to exit..."
nl: .asciiz "\n"
# array: .word 0,0,0,0,0,0,0,0,0,0


Related Solutions

write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers....
Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers. The program will store these numbers in an array in memory (sequential memory locations). It will then print out the list of numbers in three different formats: The numbers will be printed each on a separate line. The numbers will be printed on a single line, with spaces between the numbers. The program will ask the user to enter a number n. The program...
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
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,...
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and compute xy
This assignment asks to create an array with 10 integer elements. Ask user to input 10...
This assignment asks to create an array with 10 integer elements. Ask user to input 10 integer values. going through all the array elements and find/print out all the prime numbers. Instructions: Only use for loops for this lab (no need to create methods or classes for this assignment). Put a comment on each line of your codes, explaining what each line of code does. basic java, please
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT