#This program demonstrate looping and branching. #author: Hornick #CS2710 - 12/16/12 .text #.text directive (default) just tells the assembler where to put the instructions in memory main: #this label is assigned the value of the address of the next instruction # if( t0==t1 ) # s0 = 0; # else # s0 = 1; beq $t0, $t1 are_equal # if(t0==t1) jump to instruction following label "are_equal" bne $t0, $t1 not_equal # if(t0!=t1) jump to instruction following label "not_equal" are_equal: addi $s0, $zero, 1 # set s0=1 if t0=t1 j continue # jump to the instruction following the "continue" label not_equal: addi $s0, $zero, 0 # set s0=1 if t0!=t1 j continue # jump to the instruction following the "continue" label (not really needed, since that's the next instruction anyway) continue: j continue # repeat this instruction forever # if( t0=t1 j repeat # jump to the instruction following the "repeat" label (not really needed, since that's the next instruction anyway) repeat: j repeat # repeat this instruction forever