Advertisement
awsmpshk

asm nikita

Dec 6th, 2020
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extrn GetStdHandle: proc,
  2. WriteConsoleA: proc,
  3. ReadConsoleA: proc,
  4. lstrlenA: proc,
  5. ExitProcess: proc
  6.  
  7. .data
  8. STACKALLOC macro arg
  9. push R15
  10. mov R15, RSP
  11. sub RSP, 8 * 4
  12. if arg
  13. sub RSP, 8 * arg
  14. endif
  15. and SPL, 0F0h
  16. endm
  17.  
  18. STACKFREE macro
  19. mov RSP, R15
  20. pop R15
  21. endm
  22.  
  23. NULL_FIFTH_ARG macro
  24. mov qword ptr[RSP + 20h], 0
  25. endm
  26.  
  27. STD_OUTPUT_HANDLE equ -11
  28. STD_INPUT_HANDLE equ -10
  29.  
  30. hStdInput dq 0
  31. hStdOutput dq 0
  32. sum dq 0
  33. aOutputHandle db 'a = ', 0
  34. bOutputHandle db 'b = ', 0
  35. sumOutputHandle db 'a + b = ', 0
  36. invalid db 'Invalid character', 0
  37. continue db 'Press any key to exit...', 0
  38.  
  39. .code
  40. Start proc
  41. STACKALLOC 1
  42. mov RCX, STD_OUTPUT_HANDLE
  43. call GetStdHandle
  44. mov hStdOutput, RAX
  45.  
  46. mov RCX, STD_INPUT_HANDLE
  47. call GetStdHandle
  48. mov hStdInput, RAX
  49.  
  50. lea RAX, aOutputHandle
  51. push RAX
  52. call StringWrite
  53.  
  54. call StringRead
  55. cmp R10, 0
  56. je invalidCharacter
  57. mov R8, RAX
  58.  
  59. lea RAX, bOutputHandle
  60. push RAX
  61. call StringWrite
  62.  
  63. call StringRead
  64. cmp R10, 0
  65. je invalidCharacter
  66. add R8, RAX
  67.  
  68. lea RAX, sumOutputHandle
  69. push RAX
  70. call StringWrite
  71.  
  72. mov RAX, R8
  73. push RAX
  74. call PrintSignedNumber
  75.  
  76. lea RAX, continue
  77. push RAX
  78. call StringWrite
  79.  
  80. call inputAwaiting
  81. call ExitProcess
  82.  
  83. invalidCharacter:
  84. lea RAX, invalid
  85. push RAX
  86. call StringWrite
  87.  
  88. lea RAX, continue
  89. push RAX
  90. call StringWrite
  91.  
  92. call ExitProcess
  93. Start endp
  94.  
  95. StringWrite proc uses RAX RCX RDX R8 R9 R10 R11, string: qword
  96. local bytesWritten: qword
  97.  
  98. STACKALLOC 1
  99.  
  100. mov RCX, string
  101. call lstrlenA
  102.  
  103. mov RCX, hStdOutput
  104. mov RDX, string
  105. mov R8, RAX
  106. lea R9, bytesWritten
  107.  
  108. NULL_FIFTH_ARG
  109. call WriteConsoleA
  110. STACKFREE
  111. ret 8
  112. StringWrite endp
  113.  
  114. StringRead proc uses RBX RCX RDX R8 R9 R10 R11
  115. local readStr[64]: byte,
  116. bytesRead: dword
  117. STACKALLOC 1
  118.  
  119. mov RCX, hStdInput
  120. lea RDX, readStr
  121. mov R8, 64
  122. lea R9, bytesRead
  123. NULL_FIFTH_ARG
  124.  
  125. call ReadConsoleA
  126.  
  127. xor RCX, RCX
  128. mov ECX, bytesRead
  129. sub ECX, 2
  130. mov readStr[RCX], 0
  131. xor RBX, RBX
  132. mov R8, 1
  133.  
  134. strReading:
  135. dec RCX
  136. cmp RCX, -1
  137. je scanningComplete
  138. mov RAX, 0
  139. mov AL, readStr[RCX]
  140. cmp AL, '-'
  141. jne eval
  142. neg RBX
  143. jmp scanningComplete
  144.  
  145. eval:
  146. cmp AL, 30h
  147. jl error
  148. cmp AL, 39h
  149. jg error
  150. add RBX, RAX
  151.  
  152. sub RAX, 30h
  153. mul R8
  154. add RBX, RAX
  155. mov RAX, 10
  156. mul R8
  157. mov R8, RAX
  158.  
  159. error:
  160. xor R10, R10
  161. STACKFREE
  162. ret
  163.  
  164. scanningComplete:
  165. mov R10, 1
  166. mov RAX, RBX
  167. STACKFREE
  168. ret
  169. StringRead endp
  170.  
  171. PrintSignedNumber proc uses RAX RCX RDX R8 R9 R10 R11, number: qword
  172. local numberStr[22]: byte
  173. xor R8, R8
  174. mov RAX, sum
  175. btc number, 63
  176. inc R8
  177. neg RAX
  178. mov RBX, 10
  179. xor RCX, RCX
  180.  
  181. digitDivision:
  182. xor RDX, RDX
  183. div RBX
  184. add RDX, '0'
  185. push RDX
  186. inc RCX
  187. cmp RAX, 0
  188. jne digitDivision
  189. jmp prohodPoStacky
  190.  
  191. prohodPoStacky:
  192. pop RDX
  193. mov numberStr[R8], DL
  194. inc R8
  195. cmp RCX, 0
  196. jne prohodPoStacky
  197. mov numberStr[R8], 0
  198. lea RAX, numberStr
  199. push RAX
  200. ret 8
  201. PrintSignedNumber endp
  202.  
  203. inputAwaiting proc uses RAX RCX RDX R8 R9 R10 R11
  204. local readStr: byte,
  205. bytesRead: dword
  206. STACKALLOC 1
  207.  
  208. lea RCX, continue
  209. call lstrlenA
  210.  
  211. mov RCX, hStdOutput
  212. lea RDX, continue
  213. mov R8, RAX
  214. lea R9, bytesRead
  215.  
  216. NULL_FIFTH_ARG
  217. call WriteConsoleA
  218.  
  219. mov RCX, hStdInput
  220. lea RDX, readStr
  221. mov R8, 1
  222. lea R9, bytesRead
  223. NULL_FIFTH_ARG
  224.  
  225. call ReadConsoleA
  226.  
  227. STACKFREE
  228. ret
  229. inputAwaiting endp
  230. end
Advertisement
RAW Paste Data Copied
Advertisement