Advertisement
duke

Bubble sort assembler APO

Mar 8th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define t0 $8 // Zacatek pole
  2. #define t1 $9 // hodnota
  3. #define t2 $10 // nasledujici hodnota
  4. #define t3 $11 // pomocna promenna
  5.  
  6. #define s0 $16
  7. #define s1 $17
  8. #define s2 $18
  9. #define s3 $19
  10. #define s4 $20
  11.  
  12. .globl    pole
  13. .data
  14. .align    2
  15.  
  16. pole:
  17. .word    5
  18. .word    3
  19. .word    4
  20. .word    1
  21. .word    2
  22.  
  23. .text
  24. .globl start
  25. .ent start
  26.  
  27. start:
  28. // Inicializace prvniho cyklu
  29. la s0, pole
  30. addi s1, $0, 0 // dolni mez i
  31. addi s2, $0, 5 // horni mez i
  32. // Inicializace druheho cyklu
  33. addi s3, $0, 0 // dolni mez j
  34. addi s4, $0, 4 // horni mez j
  35. outercycle:
  36. beq s1, s2, alldone // i==5
  37. add t0, $0, s0 // zpet na zacatek pole
  38. addi s3, $0, 0 // vynulovat j
  39. addi s1, s1, 0x1 // i++
  40. j innercycle
  41. nop
  42. innercycle:
  43. beq s3, s4, outercycle
  44. nop
  45. lw t1, 0x0(t0) // nactu promenne
  46. lw t2, 0x4(t0)
  47. bgt t1, t2 , swap
  48. nop
  49. swapdone:
  50. addi t0, t0, 0x4 // posun v poli
  51. addi s3, s3, 0x1 // j++
  52. j innercycle // dalsi kolo cyklu
  53. nop
  54. swap:
  55. add t3, $0, t1 // docasne ulozim t1
  56. sw t2, 0x0(t0) // a prehodim hodnoty
  57. sw t3, 0x4(t0)
  58. j swapdone
  59. nop
  60. alldone:
  61. nop
  62. .end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement