Advertisement
JKattackk

B

Apr 2nd, 2022 (edited)
3,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.08 KB | None | 0 0
  1. /*-----------------DO NOT MODIFY--------*/
  2. .global Sort
  3. .global printf
  4. .global cr
  5. .extern value
  6. .extern getstring
  7. .syntax unified
  8.  
  9. .text
  10. Sort:
  11. /*-----------------Students write their subroutine here--------------------*/
  12. PUSH {LR};
  13. PUSH {R4};
  14. LDR R0, [SP, 0x8];        //size
  15.  
  16. .equ arrAdd, 0x20001000;  //array address
  17. LDR R1,= arrAdd;
  18.  
  19. SUB R0, 0x1;
  20. LSL R0, 0x2;
  21. ADD R0, R1;               //converting size to final adress of array
  22.  
  23. loop:
  24. LDR R3, [R1], 0x4;        //n, n+1 value of array
  25. LDR R4, [R1];
  26.  
  27. CMP R3, R4;               //compare and swap if in wrong order
  28. ITTE GT;
  29. STRGT R3, [R1];
  30. MOVGT R3, R4;
  31. STRLE R4, [R1];
  32. SUB R1, 0x4;
  33. STR R3, [R1], 0x4;
  34.  
  35. CMP R1, R0;               //see if array adress is final array address
  36. ITT EQ;
  37. SUBEQ R0, 0x4;            //if so, sub 4 from final array adress
  38. LDREQ R1,= arrAdd;        //reset array adress
  39.  
  40. CMP R1, R0;               //see if final array adress is starting array adress
  41. BNE loop;                 //if not branch to start of loop
  42.  
  43. POP {R4}
  44. POP {LR};
  45. BX LR;
  46. /*-------Code ends here ---------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement