# 1to10.s -- a program that prints the numbers 1-10 on the screen # Register purpose: # $s0 = number to be printed & loop control variable # $s1 = sentinel value telling the last number to print # $v0 = identifies which operating system I/O function to perform # (1 means integer output, 4 is for string output # 10 means quit the program) # $a0 = the argument to I/O function (copied from $s0) .data nl: .asciiz "\n" # newline string .text main: li $s0, 1 # initial value of loop control var li $s1, 10 # final number to print loop: bgt $s0, $s1, exit_loop # quit loop when i > last number li $v0, 1 # print the integer from $s0 move $a0, $s0 syscall li $v0, 4 # print newline la $a0, nl syscall addi $s0, $s0, 1 # prepare $s0 for the next iteration j loop # do the next iteration exit_loop: li $v0, 10 # end of the program syscall