ECE 242-Homework Assignment #12 Spring 2018 Write a MIPS program that adds up al
ID: 3708553 • Letter: E
Question
ECE 242-Homework Assignment #12 Spring 2018 Write a MIPS program that adds up all numbers divisible by 7 between two limits, e.g., from 21 to 100 Your program must use at least one loop Your program should store the sum in register St6 Include all necessary global and local comments Be sure to run your program and check the results The name of your program should be your last name (or its first eight letters), with no extensions . . . · Create the package in the usual form and submit your program file along with representative data and results as paper copies in the class on or before the due date.Explanation / Answer
.data
prompt_lower: .asciiz "Enter lower limit :"
prompt_upper: .asciiz "Enter upper limit :"
result_msg: .asciiz "The sum of numbers divisible by 7 between given limits is :"
.text
main:
li $s0, 0 #Sets $s0 0
li $v0, 4 #Get user input
la $a0, prompt_lower #Displays "Enter lower limit :"
syscall
li $v0, 5 #Gets users integer
syscall
move $t0, $v0 #Stores user input to $t0
li $v0,4 #Get user input
la $a0,prompt_lower #Display "Enter upper limit :"
syscall
li $v0 5 #Get int from user
syscall
move $t1, $v0
addi $t1,$t1,1
li $t4,0 #sum
LOOP:
beq $t0,$t1,LOOP_END
li $t2,7 #loads $t2 with 7
divu $t0, $t2 #Divides $t0/$t2
mfhi $t3
bnez $t3,NEXT_ELEMENT
add $t4,$t4,$t0
NEXT_ELEMENT:
addi $t0,$t0,1
jmp LOOP
LOOP_END:
li $v0, 4
la $a0, result_msg #Displays "The sum of numbers divisible by 7 between given limits is :"
syscall
li $v0,1
move $a0,t4
syscall
exit:
li $v0 10
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.