Guest User

ARM assembly

a guest
Jan 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. .text
  2. .globl _start
  3.  
  4. start = 0
  5. max = 100
  6.  
  7. _start:
  8. /*setup initial loop counter */
  9. mov x19, start
  10.  
  11. loop:
  12. /* Start loop here */
  13.  
  14. /* Print the Loop string */
  15. mov x0, 1 /* file descriptor: 1 is stdout */
  16. adr x1, loop_msg /* message location (memory address) */
  17. mov x2, loop_msg_len /* message length (bytes) */
  18.  
  19. mov x8, 64 /* write is syscall #64 */
  20. svc 0 /* invoke syscall */
  21.  
  22. /* Print Numbers */
  23.  
  24. mov x20, num_msg_len
  25. udiv x21, x19, x20
  26. cmp x19, x20
  27.  
  28. mov x0, 1 /* file descriptor: 1 is stdout */
  29. adr x1, num_msg /* message location (memory address) */
  30. add x1, x1, x21 /* add the loop count */
  31. mov x2, 1 /* message length (bytes) */
  32.  
  33. mov x8, 64 /* write is syscall #64 */
  34. svc 0 /* invoke syscall */
  35.  
  36. msub x21, x20, x21, x19
  37.  
  38. mov x0, 1 /* file descriptor: 1 is stdout */
  39. adr x1, num_msg /* message location (memory address) */
  40. add x1, x1, x21 /* add the loop count */
  41. mov x2, 1 /* message length (bytes) */
  42.  
  43. mov x8, 64 /* write is syscall #64 */
  44. svc 0 /* invoke syscall */
  45.  
  46.  
  47. /* Print newline */
  48.  
  49. mov x0, 1 /* file descriptor: 1 is stdout */
  50. adr x1, nl_msg /* message location (memory address) */
  51. mov x2, nl_msg_len /* message length (bytes) */
  52.  
  53. mov x8, 64 /* write is syscall #64 */
  54. svc 0 /* invoke syscall */
  55.  
  56. /* Increment loop */
  57. add x19, x19, 1
  58. /* compare the loop counter (x19) to the max value */
  59. cmp x19, max
  60. /* branch if less then the max */
  61. b.lt loop
  62.  
  63. mov x0, 0 /* status -> 0 */
  64. mov x8, 93 /* exit is syscall #93 */
  65. svc 0 /* invoke syscall */
  66.  
  67. .data
  68.  
  69. loop_msg: .ascii "Loop: "
  70. loop_msg_len = . - loop_msg
  71.  
  72. num_msg: .ascii "0123456789"
  73. num_msg_len = . - num_msg
  74.  
  75. nl_msg: .ascii "\n"
  76. nl_msg_len = . - nl_msg
Add Comment
Please, Sign In to add comment