In: Computer Science
write a program that takes the input value from the user and calculate the sum from that number to zero in MIPS
.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.