Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. section .text
  2. global _start
  3.  
  4. _start:
  5. mov ecx, 0
  6.  
  7. l1:
  8. inc ecx
  9. mov eax, ecx
  10. call printIntLB
  11. cmp ecx, 14
  12. jne l1
  13. call quit
  14.  
  15. printIntLB:
  16. call printInt
  17. push eax
  18. mov eax, 0Ah
  19. push eax
  20. mov eax, esp
  21. call printString
  22. pop eax
  23. pop eax
  24. ret
  25.  
  26. printInt:
  27. push eax
  28. push ecx
  29. push edx
  30. push esi
  31. mov ecx, 0
  32.  
  33. divideLoop:
  34. inc ecx
  35. mov edx, 0
  36. mov esi, 10
  37. idiv esi
  38. add edx, 48
  39. push edx
  40. cmp eax, 0
  41. jnz divideLoop
  42.  
  43. printLoop:
  44. dec ecx
  45. mov eax, esp
  46. call printString
  47. pop eax
  48. cmp ecx, 0
  49. jnz printLoop
  50.  
  51. pop esi
  52. pop edx
  53. pop ecx
  54. pop eax
  55. ret
  56.  
  57. printString:
  58. push edx
  59. push ecx
  60. push ebx
  61. push eax
  62. call lengthString
  63.  
  64. mov edx, eax
  65. pop eax
  66.  
  67. mov ecx, eax
  68. mov ebx, 1
  69. mov eax, 4
  70. int 80h
  71.  
  72. pop ebx
  73. pop ecx
  74. pop edx
  75. ret
  76.  
  77. lengthString:
  78. push ebx
  79. mov ebx, eax
  80.  
  81. nextchar:
  82. cmp byte [eax], 0
  83. jz done
  84. inc eax
  85. jmp nextchar
  86.  
  87. done:
  88. sub eax, ebx
  89. pop ebx
  90. ret
  91.  
  92. quit:
  93. mov ebx, 0
  94. mov eax, 1
  95. int 80h
  96. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement