Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- array: .word 0:20
- endline: .asciiz "\n"
- firstnumber: .asciiz "Give me the first number of the sequence"
- step: .asciiz "Give me the step of this sequence"
- space: .asciiz " "
- sum: .asciiz "The sum of the 20 first terms of the sequence is:"
- .text
- main:
- la $t0, array #we are gonna use $t0 as a pointer
- la $a0, firstnumber
- li $v0, 4
- syscall #Print firstnumber message
- li $v0, 5 #Get First integer from keyboard
- syscall
- sw $a0, ($t0) #saves the first integer to the first array Cell
- la $a0, step
- li $v0, 4
- syscall #Print step message
- li $v1, 5 #Get step from keyboard
- syscall
- move $t1 , $v1
- li $t2 , 0 #counter for array iteration
- li $t3 , 20 #limit for array iteration
- li $t5, 0 #initialize sum of sequence
- firstloop:
- blt $t2,$t3,secondloop #if counter is out of bounds, do to second loop
- lw $t4, array + $t2 #load number from iterator's position
- add $t2,$t2,4 #ready to iterate to the next array cell
- add $t4, $t4, $t1 #calculate next sequence number
- sw $t4, array + $t2 #store next number to the next array cell
- j firstloop
- secondloop:
- bltz $t2, result
- sub $t2, $t2, 4
- lw $t4, array + $t2
- move $a0, $t4
- li $v0, 1
- add $t5, $t5, $t4
- j secondloop
- result:
- li $v0, 10 #exit system call
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement