Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .586
- .model flat, stdcall
- option casemap :none
- .stack 4096
- ExitProcess proto,dwExitCode:dword
- GetStdHandle proto :dword
- ReadConsoleA proto :dword, :dword, :dword, :dword, :dword
- WriteConsoleA proto :dword, :dword, :dword, :dword, :dword
- .data
- STD_INPUT_HANDLE equ -10
- STD_OUTPUT_HANDLE equ -11
- bufSize = 80
- inputHandle DWORD ?
- buffer db bufSize dup(?)
- bytes_read DWORD ?
- sum_string db "The number was ",0
- enter_value db "Enter a value",0
- choose_conversion db "Choose 1 to convert to Celsius or 2 to convert to Fahrenheit",0
- outputHandle DWORD ?
- bytes_written dd ?
- actualNumber dw 0
- asciiBuf db 4 dup (0)
- VarC db ?
- VarF db ?
- VarX db ?
- VarMinus db ?
- .code
- main proc
- mov eax,0
- mov ebx,0
- mov ecx,0
- mov edx,0
- invoke GetStdHandle, STD_OUTPUT_HANDLE
- mov outputHandle, eax
- invoke GetStdHandle, STD_INPUT_HANDLE
- mov inputHandle, eax
- mov eax, LENGTHOF enter_value
- invoke WriteConsoleA, outputHandle, addr enter_value, eax, addr bytes_written, 0
- call readString
- mov eax, LENGTHOF choose_conversion
- invoke WriteConsoleA, outputHandle, addr choose_conversion, eax, addr bytes_written, 0
- invoke ReadConsoleA, inputHandle, addr buffer, bufSize, addr bytes_read,0
- mov eax,0
- mov eax,bytes_written
- push 0
- mov bl, buffer
- mov al, 31h
- CMP al,bl
- JE FtoC
- JMP CtoF
- CtoF:
- mov ax, actualNumber
- mov bl, 9
- mul bl
- mov bl,5
- div bl
- add al,32
- mov VarX, al
- call writeString
- invoke ExitProcess,0
- FtoC:
- mov ax, actualNumber
- sub ax, 32
- CMP eax, 65000
- JGE Negative
- mov bl, 5
- mul bl
- mov bl, 9
- div bl
- mov VarX, al
- call writeString
- invoke ExitProcess,0
- Negative:
- mov ecx, 65536
- sub ecx, eax
- mov eax, ecx
- mov bl,5
- mul bl
- mov bl, 9
- div bl
- mov VarX, al
- call writeNegativeString
- invoke ExitProcess,0
- main endp
- readString PROC
- invoke ReadConsoleA, inputHandle, addr buffer, bufSize, addr bytes_read,0
- sub bytes_read, 2 ; -2 to remove cr,lf
- mov ebx,0
- mov al, byte ptr buffer+[ebx]
- sub al,30h
- add [actualNumber],ax
- getNext:
- inc bx
- cmp ebx,bytes_read
- jz cont
- mov ax,10
- mul [actualNumber]
- mov actualNumber,ax
- mov al, byte ptr buffer+[ebx]
- sub al,30h
- add actualNumber,ax
- jmp getNext
- cont:
- ret
- readString ENDP
- writeNegativeString PROC
- invoke GetStdHandle, STD_OUTPUT_HANDLE
- mov outputHandle, eax
- mov eax,LENGTHOF VarX ;length of sum_string
- mov al,[VarX]
- mov cl,10
- mov bl,3
- nextNum:
- div cl
- add ah,30h
- mov byte ptr asciiBuf+[ebx],ah
- dec ebx
- mov ah,0
- cmp al,0
- ja nextNum
- mov eax, LENGTHOF VarMinus
- mov VarMinus, 45
- invoke WriteConsoleA, outputHandle, addr VarMinus, eax, addr bytes_written,0
- mov eax,4
- invoke WriteConsoleA, outputHandle, addr asciiBuf, eax, addr bytes_written, 0
- ret
- writeNegativeString ENDP
- writeString PROC
- invoke GetStdHandle, STD_OUTPUT_HANDLE
- mov outputHandle, eax
- mov eax,LENGTHOF VarX ;length of sum_string
- mov al,[VarX]
- mov cl,10
- mov bl,3
- nextNum:
- div cl
- add ah,30h
- mov byte ptr asciiBuf+[ebx],ah
- dec ebx
- mov ah,0
- cmp al,0
- ja nextNum
- mov eax,4
- invoke WriteConsoleA, outputHandle, addr asciiBuf, eax, addr bytes_written, 0
- ret
- writeString ENDP
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement