Advertisement
Guest User

arma2

a guest
Jan 22nd, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.19 KB | None | 0 0
  1.     ENTRY
  2.     B main
  3.     ;;  array   DEFW    4, 15, 47, 23, 18, 10, 22, 6, 37, 28
  4.  
  5. array   DEFW    8, 4, 17, 23, 40, 43, 35, 21, 4, 34
  6.    
  7. message DEFB    "Sorted list is \0"
  8. msg2    DEFB    " made up of \0"
  9. msg3    DEFB    " and \0"
  10. msg4    DEFB    "\n\0"
  11.     ALIGN
  12.  
  13.         ; BUG
  14.         ; LDR used instead of ADR
  15. main    LDR R0,array
  16.         SUB R1,R0,#4
  17.  
  18.         MOV R4,#1
  19.         B iLoopCond
  20. iLoop   LDR R6, [R0, R4 LSL #2]
  21.         MOV R5,R4               ; j is in r5
  22.  
  23.         B cLoopCond
  24.  
  25.         ; BUG
  26.         ; Mulitplies by 8, not by 4
  27. cLoop   STR R7, [r0, r5 LSL #3]
  28.         ; BUG
  29.         ; Subtracts 4 (i.e. size of one int, but shift is already multiplying by four)
  30.         sub r5,r5,#4
  31.  
  32. cLoopCond
  33.         CMP R5, #0
  34.         BLE cLoopEnd
  35.         LDR R7, [R1, R5 LSL #2]
  36.         CMP R7, R6
  37.         BGT cLoop
  38.  
  39. cLoopEnd
  40.         ; BUG
  41.         ; Wrong loop counter used to store value in list (ends up back where it strateds)
  42.         STR R6,[R0, R4 LSL #2]
  43.  
  44.         ; BUG
  45.         ; R4 (outer loop counter) never incremented
  46. iLoopCond
  47.         CMP R4,#10
  48.         BLT iLoop
  49.  
  50.         ADR R0, message
  51.         SWI 3
  52.  
  53.         ADR R0, array
  54.         MOV R1, #10
  55.         BL PrintArray
  56.  
  57.         ADR R0,msg4
  58.         SWI 3
  59.  
  60.  
  61.         SWI 2
  62.  
  63.  
  64. PrintArray
  65.         MOV R3,R0
  66.         B   ploopCond
  67. ploop   LDR R0, [R3], #4
  68.         SWI 4
  69.         MOV R0,#','
  70.         SWI 0
  71.         SUB R1,R1,#1
  72. ploopCond
  73.         CMP R1,#0
  74.         BGT ploop
  75.         MOV PC,R14
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement