Question

In: Computer Science

write a program that takes the input value from the user and calculate the sum from...

  • write a program that takes the input value from the user and calculate the sum from that number to zero in MIPS

Solutions

Expert Solution

.text
.global main
main: 
li $v0,4            #print message msg1, code used is 4
la $a0,msg1
syscall
li $v0,5       # to read  N from user, code is 5 and integer stored in $v0
syscall
move $t0,$v0             # $t0=N.if pseudo instruction not works, use addi $t0,$v0,$zero
li $t1,0     #initialize t1=0 , so store sum
loop:    add $t1,$t1,$t0                # To find sum
             li $t3,1                               # $t3=1
            sub $t0,$t0,$t3                   # $t0=$t0-1
            beq $t0,$zer0,exit             # if $t0=0, then goto exit
           j loop                                    # if $t0≠0, repeat the loop
exit:    li  $v0,4                                  #to print messge sum=
            la $a0,msg2
           syscall
           li $v0,1                                 # to print sum stored in $t1
          move $a0,$t1   # if not working, use addi $a0,$t1,$zero
          syscall
         li $v0,10                         #to exit
         syscall
.data
msg1:    .asciiz   “enter the value of N:”
msg2:    .asciiz “sum=”

Note: if move instruction, which is a psedoinstruction in MIPS QTSPIM, use addi instruction as given as comment.


Related Solutions

write a program that takes two input values from the user and calculate the division if...
write a program that takes two input values from the user and calculate the division if the first number is greater than the second one otherwise calculate the multiplication.
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Q1-      Write a program that takes a list of values as an input from the user....
Q1-      Write a program that takes a list of values as an input from the user. The program should further ask the user about sorting the list in ascending or descending order. It is desirable to use Arraylist/Vector in place of simple arrays. (Object Oriented Programming java)
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT)...
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT) AND CALCULATES THE NTH FIBONACCI SUM USING RECURSION. EXAMPLE: OLD VERSION 0,1,1,2,3.. USING USER INPUT: 0, N, M ,N+M, (N+M)+M PART 2: WRITE THE SAME PROGRAM USING USER INPUT BUT USING A LOOP IN STEAD OF RECURSION. PYTHON
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Write a program to calculate the amount of money in an account: The user will input...
Write a program to calculate the amount of money in an account: The user will input initial deposit and the number of years to leave that money in the account. The interest is constant at 0.5% for the entire length of time. The output will be the balance, with interest compounded annually. (simple interest formula: interest = principal * rate) What variables will you need to complete the program? What “controls” will you need for the program? What formula will...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a Java program that uses printf, and takes user input to find the name of...
Write a Java program that uses printf, and takes user input to find the name of the File. FileCompare (20) Write a program that compares to files line by line, and counts the number of lines that are different. You can use file1.txt and file2.txt when testing your program, but you must ask for the file names in the input. main Interactively requests the names of the two files, after creating the Scanner for the keyboard. Creates a Scanner for...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Create the logic for a rhyming program that takes in five words from a user input...
Create the logic for a rhyming program that takes in five words from a user input and replaces the selected rhyming words with the user's input, then creates and displays the Humpty Dumpty rhyme with the five words from the user input. Hint: 1. You will use the sentinel values: start and stop 2. The program will ask the user for 5 words. 3. The program will store the 5 words 4. The program outputs the rhyme replacing the ____...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT