Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. .586
  2. .model flat, stdcall
  3. option casemap :none
  4. .stack 4096
  5. ExitProcess proto,dwExitCode:dword
  6.  
  7. GetStdHandle proto :dword
  8. ReadConsoleA proto :dword, :dword, :dword, :dword, :dword
  9. WriteConsoleA proto :dword, :dword, :dword, :dword, :dword
  10.  
  11.  
  12. .data
  13. STD_INPUT_HANDLE equ -10
  14. STD_OUTPUT_HANDLE equ -11
  15. bufSize = 80
  16. inputHandle DWORD ?
  17. buffer db bufSize dup(?)
  18. bytes_read DWORD ?
  19. sum_string db "The number was ",0
  20. enter_value db "Enter a value",0
  21. choose_conversion db "Choose 1 to convert to Celsius or 2 to convert to Fahrenheit",0
  22. outputHandle DWORD ?
  23. bytes_written dd ?
  24. actualNumber dw 0
  25. asciiBuf db 4 dup (0)
  26. VarC db ?
  27. VarF db ?
  28. VarX db ?
  29. VarMinus db ?
  30.  
  31.  
  32. .code
  33. main proc
  34. mov eax,0
  35. mov ebx,0
  36. mov ecx,0
  37. mov edx,0
  38.  
  39. invoke GetStdHandle, STD_OUTPUT_HANDLE
  40. mov outputHandle, eax
  41.  
  42. invoke GetStdHandle, STD_INPUT_HANDLE
  43. mov inputHandle, eax
  44.  
  45. mov eax, LENGTHOF enter_value
  46. invoke WriteConsoleA, outputHandle, addr enter_value, eax, addr bytes_written, 0
  47. call readString
  48.  
  49. mov eax, LENGTHOF choose_conversion
  50. invoke WriteConsoleA, outputHandle, addr choose_conversion, eax, addr bytes_written, 0
  51. invoke ReadConsoleA, inputHandle, addr buffer, bufSize, addr bytes_read,0
  52. mov eax,0
  53. mov eax,bytes_written
  54. push 0
  55. mov bl, buffer
  56. mov al, 31h
  57. CMP al,bl
  58. JE FtoC
  59. JMP CtoF
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. CtoF:
  68. mov ax, actualNumber
  69. mov bl, 9
  70. mul bl
  71. mov bl,5
  72. div bl
  73. add al,32
  74. mov VarX, al
  75. call writeString
  76. invoke ExitProcess,0
  77.  
  78.  
  79. FtoC:
  80. mov ax, actualNumber
  81. sub ax, 32
  82. CMP eax, 65000
  83. JGE Negative
  84. mov bl, 5
  85. mul bl
  86. mov bl, 9
  87. div bl
  88. mov VarX, al
  89. call writeString
  90. invoke ExitProcess,0
  91.  
  92. Negative:
  93. mov ecx, 65536
  94. sub ecx, eax
  95. mov eax, ecx
  96. mov bl,5
  97. mul bl
  98. mov bl, 9
  99. div bl
  100. mov VarX, al
  101. call writeNegativeString
  102. invoke ExitProcess,0
  103.  
  104. main endp
  105. readString PROC
  106.  
  107.  
  108.  
  109. invoke ReadConsoleA, inputHandle, addr buffer, bufSize, addr bytes_read,0
  110. sub bytes_read, 2 ; -2 to remove cr,lf
  111. mov ebx,0
  112.  
  113. mov al, byte ptr buffer+[ebx]
  114. sub al,30h
  115. add [actualNumber],ax
  116. getNext:
  117. inc bx
  118. cmp ebx,bytes_read
  119. jz cont
  120. mov ax,10
  121. mul [actualNumber]
  122. mov actualNumber,ax
  123. mov al, byte ptr buffer+[ebx]
  124. sub al,30h
  125. add actualNumber,ax
  126.  
  127. jmp getNext
  128. cont:
  129. ret
  130.  
  131. readString ENDP
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. writeNegativeString PROC
  139. invoke GetStdHandle, STD_OUTPUT_HANDLE
  140. mov outputHandle, eax
  141. mov eax,LENGTHOF VarX ;length of sum_string
  142. mov al,[VarX]
  143. mov cl,10
  144. mov bl,3
  145. nextNum:
  146. div cl
  147. add ah,30h
  148. mov byte ptr asciiBuf+[ebx],ah
  149. dec ebx
  150. mov ah,0
  151. cmp al,0
  152. ja nextNum
  153.  
  154. mov eax, LENGTHOF VarMinus
  155. mov VarMinus, 45
  156. invoke WriteConsoleA, outputHandle, addr VarMinus, eax, addr bytes_written,0
  157.  
  158. mov eax,4
  159. invoke WriteConsoleA, outputHandle, addr asciiBuf, eax, addr bytes_written, 0
  160.  
  161.  
  162. ret
  163. writeNegativeString ENDP
  164. writeString PROC
  165. invoke GetStdHandle, STD_OUTPUT_HANDLE
  166. mov outputHandle, eax
  167. mov eax,LENGTHOF VarX ;length of sum_string
  168. mov al,[VarX]
  169. mov cl,10
  170. mov bl,3
  171. nextNum:
  172. div cl
  173. add ah,30h
  174. mov byte ptr asciiBuf+[ebx],ah
  175. dec ebx
  176. mov ah,0
  177. cmp al,0
  178. ja nextNum
  179.  
  180. mov eax,4
  181. invoke WriteConsoleA, outputHandle, addr asciiBuf, eax, addr bytes_written, 0
  182.  
  183.  
  184. ret
  185. writeString ENDP
  186.  
  187.  
  188. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement