Guest User

Untitled

a guest
Mar 10th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .text
  2. .globl check_remaining_columns
  3. check_remaining_columns:
  4.                 ## $a0 = matrix
  5.                 ## $a1 = list
  6.                 ## $a2 = bitmask
  7.  
  8.     sub $sp, $sp, 24    ## getting memory space
  9.     sw $ra, 0($sp)      ## storing ra into stack frame
  10.     sw $s0, 4($sp)      ## getting space for s0
  11.     sw $s1, 8($sp)      ## getting space for s1
  12.     sw $s2, 12($sp)     ## getting space for s2
  13.     sw $s3, 16($sp)     ## getting space for s3
  14.     sw $s4, 20($sp)     ## getting space for s4
  15.  
  16.     move $s0, $a0       ## s0 = matrix
  17.     move $s1, $a1       ## s1 = list
  18.  
  19.     li $s2, 0       ## s2 = i = 0
  20.     lw $s3, 0($s1)      ## $s3 = list->size
  21.     li $s4, 1       ## 1L: which means that it is a long that can be treated as an int.
  22.  
  23. for:    bge $s2, $s3, end1  ## branch if i >= list->size
  24.     sllv $t1, $s4, $s2  ## 1L << i
  25.     and $t2, $t1, $a2   ## (1L << i) & bitmask. This is 1 or 0.
  26.     li $t3, 0       ## t3 = 0 to compare in if-statement
  27.     bne $t3, $t2, next  ## if (1L << i) & bitmask != 0 then continue to next iteration.
  28.     add $s2, $s2, 1     ## ++i
  29.     j for           ## jumps to for loop
  30.    
  31. next:   move $a0,$s0        ## a0 = s0 = matrix
  32.     move $a1,$s1        ## a1 = s1 = list
  33.     move $a2,$s2        ## a2 = s2 = i = row   
  34.     jal any_matrix_column_matches_list_row  ## $v0 = 1 or 0
  35.     li $t0, 0       ## $t0 = 0 to compare in if-loop
  36.     beq $t0, $v0, end2  ## if ($v0 = 0) then branch to end2
  37.     li $v1, 0       ## return 0
  38.     j stack         ## jump to stack to put memory back
  39.     jr $ra          ## return address
  40.     add $s2, $s2, 1     ## ++i
  41.     j for           ## jumps to for loop
  42.  
  43. end1:   li $v1, 1       ## return 1
  44.     j stack         ## jump to stack to put memory back
  45.     jr $ra          ## return address
  46.  
  47. end2:   add $s2, $s2, 1     ## ++i
  48.     j for           ## jumps to for loop
  49.  
  50. stack:  lw $ra, 0($sp)      ## ra into stack frame
  51.     lw $s0, 4($sp)      ## space for s0
  52.     lw $s1, 8($sp)      ## space for s1
  53.     lw $s2, 12($sp)     ## space for s2
  54.     lw $s3, 16($sp)     ## space for s3
  55.     lw $s4, 20($sp)     ## space for s4
  56.     add $sp, $sp, 24    ## putting space back into stack frame
  57.     jr $ra          ## return address
Advertisement
Add Comment
Please, Sign In to add comment