User:Xzou


 * 1) threeSum.asm
 * 2) Sum all integers, the odds, the evens
 * 1) Sum all integers, the odds, the evens


 * 1) Registers:
 * 2)  $7 -- used to test odd vs even
 * 3)  $8 -- count
 * 4)  $9 -- pointer to the array entry
 * 5) $10 -- current array entry
 * 6) $11 -- sum of all integers
 * 7) $12 -- sum of odds
 * 8) $13 -- sum of evens
 * 9) $14 -- odd or even flag
 * 10) $15 -- length of the array

.text .globl main main:   ori      $8,$0,0        #  count = 0 ori     $7,$0,0        #  flag = 0 ori     $11,$0,0       #  sum = 0 ori     $12,$0,0       #  odds = 0 ori     $13,$0,0       #  evens = 0 lui     $9,0x1000      #  point at SIZE
 * 1) Initialize

lw      $15,0($9)      #  get SIZE sll     $0,$0,0        #  load delay addiu   $9,$9,4        #  point to first entry lw      $10,0($9)      #  get start number sll     $0,$0,0        #  load delay

loop:   beq      $8,$15,done sll     $0,$0,0        #  branch delay
 * 1) while  count < SIZE do

addiu   $10, $10,1	 #  get current number addu    $11,$11,$10    #  add to sum
 * 1) get entry, add to sum

andi    $7, $10,1      #  set flag bne     $7,$0,odd      #  branch if odd sll     $0,$0,0        #  branch delay addu    $13,$13,$10    #  even: add to evens j       ifend sll     $0,$0,0        #  branch delay
 * 1)  test odds or evens

odd:    addu     $12,$12,$10    #  odd: add to odds

ifend:  addiu    $8,$8,1        # count++ j       loop sll     $0,$0,0        #  branch delay

done:   sll      $0,$0,0        # target for branch
 * 1) finish

.data size:  .word  100 array: .word  0


 * 1) strlen.asm
 * 2) Count the characters in a string
 * 3) Registers:
 * 4)  $7 -- flag indicate whther to capitalize
 * 5)  $8 -- upper or lower flag
 * 6)  $9 -- pointer to the char
 * 7) $10 -- the char (in low order byte)
 * 8) $11 -- converter
 * 1) $10 -- the char (in low order byte)
 * 2) $11 -- converter

.text .globl main main:   ori      $7,$0,1        #  flag = 1 ori     $8,$0,0        #  upper or lower flag = 0 lui     $9,0x1000       #  point at first char ori     $11,$0,32       # converter=32, space sign loop:   lbu      $10,0($9)      # get the char sll     $0,$0,0        # branch delay beq     $10,$0,done    # exit loop if char == null sll     $0,$0,0        # branch delay beq     $7,$0,Ncap     # do not capitalize sll     $0,$0,0        # branch delay sltiu   $8, $10, 97 bne     $8, $0, upper sll     $0,$0,0        # branch delay subu    $10,$10,$11    # convert cahr to lower case sb      $10,0($9)
 * 1) Initialize
 * 1) while not ch==null do

upper:  ori      $7,$0,0	 #clear flag

Ncap:	 bne     $10,$11,continue sll     $0,$0,0        # branch delay ori     $7,$0,1

continue:ori $8,$0,0 addiu   $9,$9,1        # point at the next char

j       loop sll     $0,$0,0        # branch delay slot

done:   sll      $0,$0,0        # target for branch
 * 1) finish

.data string: .asciiz  "in a     Hole    in    the    ground   There Lived a Hobbit"