# Lab 2 Matthew Pearson 9/20/06 ######################################## .data promptx: .asciiz "Enter x: " prompty: .asciiz "Enter y: " agb: .asciiz "\na is greater than b\n" altb: .asciiz "\na is less than b\n" aeb: .asciiz "\na is equal to b\n" value: .asciiz "\nStill in Loop and value of x is: " moveon: .asciiz "\nMove onto for loop? 0=Yes 1=No: " .text # Greater than, less than, or equal to ################################# main: test: li $v0, 4 #load sys code for printing strings la $a0, promptx #load address of string to be printed syscall #prints the string li $v0, 5 #load sys code for reading ints syscall #reads it move $t0, $v0 #$v0 = #v0 li $v0, 4 #load sys code for printing strings la $a0, prompty #load address of string to be printed syscall #prints the string li $v0, 5 #load sys code for reading ints syscall #reads the int move $t1, $v0 #$t1=$v0 beq $t0, $t1, equal #if $t0 = $t1 go to equal blt $t0, $t1, lessthan #if t0 < t1 go to lessthan bgt $t0, $t1, greaterthan #if to > t1 go to greaterthan equal: la $a0, aeb #load address of string to be printed b result #skip to the result section greaterthan: la $a0, agb #load address of string to be printed b result #skip to the result section lessthan: la $a0, altb #load address of string to be printed result: li $v0, 4 #load sys code for printing strings syscall #prints the string li $v0, 4 #load sys code for printing strings la $a0, moveon #load address of string to be printed syscall #prints the string li $v0, 5 #load sys code for reading ints syscall #reads the int move $t1, $v0 #$t1=$v0 bgtz $t1, test #runs the test again if user desires b loopstart #runs the loop # FOR loop code ######################################################### loopstart: li $t0, 0 #loads 0 into $t0 li $t1, 10 #loads 10 into $t1 loop: blt $t0, $t1, increment #if $t0 is less than $t1 go to the increment routine. beq $t0, $t1, endloop #if $to is equal to $t1 go to the endloop routine. increment: li $v0, 4 #load sys code for printing strings la $a0, value #load address of string to be printed syscall #prints the string li $v0, 1 #load sys code for printing ints move $a0, $t0 #$a0 == $t0 syscall #prints x addi $t0, 1 #increments x b loop #goes to loop endloop: li $v0, 4 #load sys code for printing strings la $a0, value #load address of string to be printed syscall #prints the string li $v0, 1 #load sys code for printing ints move $a0, $t0 #$a0 == $t0 syscall #prints x