Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. .text
  2. .global main
  3.  
  4. // r5 - capasity
  5. // r6 - ptr
  6. // r7 - size
  7. main:
  8. push {r5, r6, r7, lr}
  9. mov r5, #1
  10. mov r7, #0
  11. mov r6, #0
  12. b reallocation
  13.  
  14. input:
  15. ldr r0, stdin_ptr
  16. ldr r0, [r0]
  17. bl fgetc
  18. cmp r0, #-1
  19. beq output
  20.  
  21. strb r0, [r6, r7]
  22. add r7, #1
  23.  
  24. cmp r7, r5
  25. blt input
  26.  
  27. add r5, r5
  28. b reallocation
  29.  
  30. reallocation:
  31. mov r0, r6
  32. mov r1, r5
  33. bl realloc
  34. mov r6, r0
  35. b input
  36.  
  37. output:
  38. sub r7, #1
  39.  
  40. ldrb r0, [r6, r7]
  41. ldr r1, stdout_ptr
  42. ldr r1, [r1]
  43. bl fputc
  44.  
  45. cmp r7, #0
  46. bgt output
  47.  
  48. b end_main
  49.  
  50. end_main:
  51. mov r0, r6
  52. bl free
  53. pop {r5, r6, r7, lr}
  54. bx lr
  55.  
  56. stdin_ptr:
  57. .word stdin
  58.  
  59. stdout_ptr:
  60. .word stdout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement