Advertisement
Guest User

Mathew Sort

a guest
Jan 23rd, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.50 KB | None | 0 0
  1. B main
  2.  
  3. array       DEFW 6, 5, 8, 2, 1, 4, 3, 7, 9
  4. size        DEFW 9
  5.  
  6.             ALIGN
  7.             ;Inputs:R0: Address of the start of the array
  8.             ;       R1: Size of the array
  9. bubble      STMFD SP!, {R4-R6}
  10.             ADD R2, R0, #4
  11.  
  12. pas_lp      MOV R6, #0
  13.             MOV R3, #0
  14.             B swp_lp_cnd
  15. swp_lp      LDR R4, [R0, R3 ASL #2]
  16.             LDR R5, [R2, R3 ASL #2]
  17.             CMP R4, R5
  18.             ; BUG
  19.             ; STRLT should be STRGT otherwise elements are sorted in reverse
  20.             STRGT R4, [R2, R3 ASL #2]
  21.             STRGT R5, [R0, R3 ASL #2]
  22.             MOV R6, #1
  23. skip_swp    ADD R3, R3, #1
  24.  
  25. swp_lp_cnd  CMP R3, R1
  26.             BLT swp_lp
  27.  
  28.             SUB R1, R1, #1
  29.  
  30.             CMP R6, #0
  31.             ; BUG
  32.             ; Should check if items were swapped (R6==1) and loop again if it isn't. (opposite condition)
  33.             BNE pas_lp
  34.  
  35.             LDMFD SP!, {R4-R6}
  36.             MOV PC, R14
  37.            
  38.  
  39. main        MOV SP, #1000
  40.             ADR R0, array
  41.             LDR R1, size
  42.             ; BUG
  43.             ; B needs to be BL to set the link register
  44.             BL bubble
  45.            
  46.             ADR R1, array
  47.             LDR R2, size
  48.             ; BUG
  49.             ; Size is used to count number of bytes. Thus needs to be multiplied by 4
  50.             ADD R2, R1, R2 ASL #2
  51.  
  52. prt_lp      LDR R0, [R1], #4
  53.             SWI 4
  54.             MOV R0, #10
  55.             SWI 0
  56. prt_lp_cnd  CMP R1, R2
  57.             BLT prt_lp
  58.             SWI 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement