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 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
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 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.
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a mips assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT