# a SAL program to add up the first n integers, # where n is a positive integer entered by the user. .data # strings for making the output look nice str1: .asciiz "Please enter a positive integer: " str2: .asciiz "The sum of the first " str3: .asciiz " integers is " newline: .byte '\n' # variable declarations n: .word 0 # user entered integer sum: .word 0 # running sum of the first n integers i: .word 0 # integer counter, 0 to n tmp: .word # used for comparisons .text __start: puts str1 get n put newline for: sub tmp,n,i bltz tmp,endfor add sum,sum,i add i,i,1 b for endfor: puts str2 put n puts str3 put sum put newline done