Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     .word   0
  3. newline:
  4.     .asciiz "\n"
  5.  
  6. datalen:
  7.     .word   0x0015  # 16
  8. data:
  9.     .word   0xffff7e81
  10.     .word   0x00000001
  11.     .word   0x00000002
  12.     .word   0xffff0001
  13.     .word   0x00000000
  14.     .word   0x00000001
  15.     .word   0xffffffff
  16.     .word   0x00000000
  17.     .word   0xe3456687
  18.     .word   0xa001aa88
  19.     .word   0xf0e159ea
  20.     .word   0x9152137b
  21.     .word   0xaab385a1
  22.     .word   0x31093c54
  23.     .word   0x42102f37
  24.     .word   0x00ee655b
  25.     .word   0x42102f37
  26.     .word   0x00ee655b
  27.     .word   0x00000001
  28.     .word   0x00000002
  29.     .word   0xffff0001
  30. .text
  31. li $s5, 0
  32. li $s0, 1
  33. li $s1, 2
  34. lw $s3, datalen
  35. la $s4, data
  36.  
  37. while:
  38.     beq $s3, $s0, print
  39.     nop
  40.     sll $s6, $s0, 2
  41.     add $s6, $s6, $s4
  42.     sub $s7, $s6, 4
  43.     lw $t5, 0($s6)
  44.     lw $t6, 0($s7)
  45.     # If (a[i - 1] <= a[i])
  46.     bge $t5, $t6, endelse
  47.     nop
  48.    
  49.     sw $t5, 0($s7)
  50.     sw  $t6, 0($s6)
  51.    
  52.     sub $s0, $s0, 1
  53.     bne $s0, $zero, while
  54.     nop
  55.     li $s0, 1
  56.     li $s1, 2
  57.     j while
  58.     nop
  59. endelse:
  60.     la $s0, ($s1)
  61.     add $s1, $s1, 1
  62.     j while
  63.     nop
  64. print:
  65.     beq $s5, $s3, exit
  66.     nop
  67.     sll $t3, $s5, 2 # Multiply the iterator times 4 (2 because its the power of 2)
  68.     addu $t3, $t3, $s4 # Gets the momoryaddress of the array
  69.    
  70.     li $v0, 1       #Prepare for printing an int
  71.     lw $a0, 0($t3)      # Load the value of the int that is going to print
  72.     syscall        
  73.    
  74.     li $v0, 4       # Prepare to print a string
  75.     la $a0, newline     # Load the string
  76.     syscall
  77.    
  78.     addi $s5, $s5, 1    # Increase the iterator by one for the loop functionality
  79.    
  80.     j print         #Jump to the top of the loop
  81.     nop
  82.    
  83. exit:
  84.     li $v0, 10
  85.     syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement