Advertisement
Guest User

Untitled

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