SPIM code of a FOR loop

	
# this program adds the numbers 1 to 10
	
	.text
main:
	move $t0, $zero		# initialize sum (t0) to 0
	move $t1, $zero		# initialize counter (t1) to 0
loop:	addi $t1, $t1, 1	# increment counter by 1
	add  $t0, $t0, $t1	# add counter to sum
	blt  $t1, 10, loop	# if counter < 10, goto loop
	
				# this is outside the loop
				# code to print the sum

	li   $v0, 1		# system call for print_int
	move $a0, $t0		# the sum to print
	syscall			# print the sum

				# code to print a newline
	li   $v0, 4		# system call for print_str
	la   $a0, newline	# address of str to print
	syscall			
				# wind up the program
	jr $ra			# return from main

	.data 
newline:.asciiz "\n"		# declare the string newline
				# note, the decl follows the use.
				# it may also be within the code as long
				# as we toggle between .text and .data
				# correctly