Advertisement
Guest User

test

a guest
Jul 30th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. ; Generated by toASM
  2. KERN_INT equ 80h
  3. SYS_OUT equ 4
  4. SYS_IN equ 3
  5. SYS_EXIT equ 1
  6. STDOUT equ 1
  7. STDIN equ 0
  8.  
  9. section .data
  10.  
  11. section .bss
  12. _sbuf resb 255
  13. _ibuf resd 1
  14. _vsbuf resd 1
  15. _v0 resd 1 ;a
  16. _v1 resd 1 ;b
  17.  
  18. section .text
  19. global _start
  20. _start:
  21. ;read(a)
  22. mov ecx, _sbuf
  23. mov edx, 255
  24. call _read
  25.  
  26. call string_to_int
  27. mov eax, [_ibuf]
  28. mov [_v0], eax
  29. ;read(b)
  30. mov ecx, _sbuf
  31. mov edx, 255
  32. call _read
  33.  
  34. call string_to_int
  35. mov eax, [_ibuf]
  36. mov [_v1], eax
  37. ;print(a)
  38. mov eax, [_v0]
  39. mov [_ibuf], eax
  40. call int_to_string
  41. mov ecx, _sbuf
  42. mov edx, 255
  43. call _print
  44. ;print(b)
  45. mov eax, [_v1]
  46. mov [_ibuf], eax
  47. call int_to_string
  48. mov ecx, _sbuf
  49. mov edx, 255
  50. call _print
  51. ._exit_point:
  52. mov eax, SYS_EXIT
  53. int KERN_INT
  54. ; Subroutines
  55. _read:
  56. push eax
  57. push ebx
  58. mov eax, SYS_IN
  59. mov ebx, STDIN
  60. int KERN_INT
  61. dec eax
  62. mov [_vsbuf], eax
  63. pop ebx
  64. pop eax
  65. ret
  66. string_to_int:
  67. push ebx
  68. push ecx
  69. push edx
  70. push esi
  71. push edi
  72. mov eax, [_vsbuf]
  73. xor edi, edi
  74. mov ebx, 0
  75. .loop:
  76. imul ebx, ebx, 10
  77. add bl, [_sbuf+edi]
  78. sub bl, '0'
  79. inc edi
  80. cmp edi, eax
  81. jl .loop
  82. mov [_ibuf], ebx
  83. pop edi
  84. pop esi
  85. pop edx
  86. pop ecx
  87. pop ebx
  88. ret
  89. _print:
  90. push eax
  91. push ebx
  92. mov eax, SYS_OUT
  93. mov ebx, STDOUT
  94. int KERN_INT
  95. pop ebx
  96. pop eax
  97. ret
  98. int_to_string:
  99. push eax
  100. push ebx
  101. push ecx
  102. push edx
  103. push esi
  104. push edi
  105. mov eax, [_ibuf]
  106. xor edi, edi
  107. mov ecx, 10
  108. .ciclo:
  109. xor edx, edx
  110. idiv ecx
  111. add edx, '0'
  112. mov [_sbuf+edi], dl
  113. inc edi
  114. cmp eax, 0
  115. jg .ciclo
  116. mov edx, edi
  117. shr edx, 1
  118. xor esi, esi
  119. .invert:
  120. mov al, [_sbuf+esi]
  121. mov bl, [_sbuf+edi]
  122. xchg al, bl
  123. mov [_sbuf+esi], al
  124. mov [_sbuf+edi], bl
  125. dec edi
  126. inc esi
  127. cmp edi, edx
  128. jg .invert
  129. pop edi
  130. pop esi
  131. pop edx
  132. pop ecx
  133. pop ebx
  134. pop eax
  135. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement