Advertisement
STANAANDREY

risc bubble sort

Oct 28th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         BRA main
  2. main    INP R0
  3.         LDR R1, STARTARR
  4.         PSH {R1}
  5.         JMS readArr
  6.         POP {R1}
  7.         PSH {R1}
  8.         JMS bsort
  9.         POP {R1}
  10.         JMS printArr
  11.         HLT
  12. readArr MOV R2, #0
  13. loopRead CMP R2, R0
  14.         BEQ doneRead
  15.         INP R3
  16.         STR R3, [R1]
  17.         ADD R1, #1
  18.         ADD R2, #1
  19.         BRA loopRead
  20. doneRead RET
  21. printArr MOV R2, #0
  22. loopPrint CMP R2, R0
  23.         BEQ donePrint
  24.         LDR R3, [R1]
  25.         OUT R3
  26.         ADD R1, #1
  27.         ADD R2, #1
  28.         BRA loopPrint
  29. donePrint RET
  30. bsort   MOV R3, #0//step
  31. bsfor1  MOV R7, R0
  32.         SUB R7, #1
  33.         CMP R3, R7
  34.         BEQ bsdone
  35.         MOV R4, #0//i
  36. bsfor2  PSH {R7}
  37.         MOV R7, R0
  38.         SUB R7, R3
  39.         SUB R7, #1
  40.         CMP R4, R7
  41.         BEQ outfor2
  42.         MOV R5, R1
  43.         ADD R5, R4
  44.         LDR R5, [R5]
  45.         MOV R6, R1
  46.         ADD R6, R4
  47.         ADD R6, #1
  48.         LDR R6, [R6]
  49.         CMP R5, R6
  50.         BLE noswap
  51.         MOV R7, R1
  52.         ADD R7, R4
  53.         STR R6, [R7]
  54.         ADD R7, #1
  55.         STR R5, [R7]
  56. noswap  POP {R7}
  57.         ADD R4, #1
  58.         BRA bsfor2
  59. outfor2 ADD R3, #1
  60.         BRA bsfor1
  61. bsdone  RET
  62. STARTARR DAT 100
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement