Преобразователь температуры Masm32 - Assembler/MASM
Формулировка задачи:
Доброе времени суток!
Я только недавно начал изучать Assembler (Masm32). Вот пытался написать преоброзователь температуры, но возникла ошибка и не понимаю в чем она состоит.
Буду благодарен любой помощи в утранении ошибки и объяснениям в чем ошибка заключалась.
.586 ; Recognise 80x86 instructions that use 32-bit .MODEL FLAT, STDCALL ; Generate code for a flat memory model option casemap :none .STACK 4096 ; Reserve 4096 bytes for stack operations ExitProcess proto dwExitCode:dword GetStdHandle proto :dword WriteConsoleA proto :dword, :dword, :dword, :dword, :dword ReadConsoleA proto :dword, :dword, :dword, :dword, :dword STD_OUTPUT_HANDLE equ -11 ; The standard output device STD_INPUT_HANDLE equ -10 ; The standard output device .DATA msg_menu1 DB 10,13, '+-------------------------------------------------------+', 10, 13, '| Welcome to the Basic Temperature Converter |', 10, 13, '+-------------------------------------------------------+', 10, 13, 0 attempt DW 0 promptUserInputNumber DB 10, 13, 'Please enter your number: ', 0 promptUserInputOperator DB 'Please enter your operator: ', 0 promptForContinue DB 10, 13, 10, 13, 'Do you want to continue? ', 10, 13, 'Press Y for yes, or N for no: ', 0 outputHandle DWORD ? bytes_written DD ? inputHandle DWORD ? bytes_read DWORD ? buffer_size = 100 bufferForSign DB buffer_size dup(?) bufferForNumber DB buffer_size dup(?) bufferForSignConf DB buffer_size dup(?) bufferConfirmation DB buffer_size dup(?) sum_string db 10, 13, "Result of your equation is ", 0 actualNumber DW 0 result DW 0 asciiBuf DB 4 dup (" ") .CODE main PROC ; The main function of this program, it is the start point cmp attempt, 1 ; Compare attempt with 1 je ElseCase ; If the result is false, then jump to the ElseCase inc attempt ; Increase attempt call menu ; Call the menu finction ElseCase: call ask_for_continue ; Jump to the ask_for_continue function main ENDP ask_for_continue PROC ; Function for asking user if he/she wants to continue comvertation with different values invoke GetStdHandle, STD_OUTPUT_HANDLE mov outputHandle, eax mov eax, LENGTHOF promptForContinue invoke WriteConsoleA, outputHandle, addr promptForContinue, eax, addr bytes_written, 0 mov eax, 0 mov eax, bytes_written mov eax, 0 invoke GetStdHandle, STD_INPUT_HANDLE mov inputHandle, eax invoke ReadConsoleA, inputHandle, addr bufferConfirmation, buffer_size, addr bytes_read, 0 CMP bufferConfirmation, 'Y' ; Compare the user's confimation with Y JE catch_user_input ; If the result is equals to true jump to the catch_user_input function CMP bufferConfirmation, 'y' ; Compare the user's confimation with y JE catch_user_input ; If the result is equals to true jump to the catch_user_input function CMP bufferConfirmation, 'N' JE finish_program CMP bufferConfirmation, 'n' JE finish_program ask_for_continue ENDP menu PROC invoke GetStdHandle, STD_OUTPUT_HANDLE mov outputHandle, eax mov eax, LENGTHOF msg_menu1 invoke WriteConsoleA, outputHandle, addr msg_menu1, eax, addr bytes_written, 0 mov eax, 0 mov eax, bytes_written mov eax, 0 call catch_user_input menu ENDP catch_user_input PROC mov bufferForSign, 0 mov bufferForNumber, 0 mov asciiBuf, 0 mov bufferConfirmation, 0 mov actualNumber, 0 invoke GetStdHandle, STD_OUTPUT_HANDLE mov outputHandle, eax mov eax, LENGTHOF promptUserInputNumber invoke WriteConsoleA, outputHandle, addr promptUserInputNumber, eax, addr bytes_written, 0 mov eax, 0 mov eax, bytes_written mov eax, 0 invoke GetStdHandle, STD_INPUT_HANDLE mov inputHandle, eax invoke ReadConsoleA, inputHandle, addr bufferForNumber, buffer_size, addr bytes_read, 0 invoke GetStdHandle, STD_OUTPUT_HANDLE mov outputHandle, eax mov eax, LENGTHOF promptUserInputOperator invoke WriteConsoleA, outputHandle, addr promptUserInputOperator, eax, addr bytes_written, 0 mov eax, 0 mov eax, bytes_written mov eax, 0 invoke GetStdHandle, STD_INPUT_HANDLE mov inputHandle, eax invoke ReadConsoleA, inputHandle, addr bufferForSign, buffer_size, addr bytes_read, 0 call convert_ascii_to_numbers catch_user_input ENDP convert_ascii_to_numbers PROC sub bytes_read, 2 ; -2 to remove cr,lf mov ebx,0 mov al, byte ptr bufferForNumber+[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 bufferForNumber+[ebx] sub al,30h add actualNumber,ax jmp getNext cont: call converter convert_ascii_to_numbers ENDP converter PROC cmp bufferForSign, 'F' je celsius_to_fahrenheit cmp bufferForSign, 'f' je celsius_to_fahrenheit cmp bufferForSign, 'C' je fahrenheit_to_celsius cmp bufferForSign, 'c' je fahrenheit_to_celsius celsius_to_fahrenheit: ; Convert celsius to fahrenheit according to this formula: f = c * 9 / 5 + 32 mov ax, 0 ; Move 0 to ax (ax = 0) mov bx, 0 ; Move 0 to bx (bx = 0) mov ax, actualNumber ; Move actualNumber to ax (ax = user's input) mov bx, 9 ; Move 9 to bx (bx = 9) mul bx ; Multiply ax by bx (ax*bx; ax = multiplication result) mov bx, 0 ; Move 0 to bx (bx = 0) mov bx, 5 ; Move 5 to bx (bx = 5) div bx ; Divide ax by bx (ax/bx; ax = result of division) add ax, 32 ; Add 32 to ax (ax + 32) mov result, ax ; Move the value of ax to result call convert_numbers_to_ascii fahrenheit_to_celsius: ; Convert fahrenheit to celsius according to this formula: c = (f - 32) * 5 / 9 mov ax, 0 ; Move 0 to ax (ax = 0) mov bx, 0 ; Move 0 to bx (bx = 0) mov ax, actualNumber ; Move actualNumber to ax (ax = user's input) mov bx, 32 ; Move 32 to bx (bx = 32) sub ax, bx mov bx, 0 mov bx, 5 mul bx mov bx, 0 mov bx, 9 mov ah, 0 div bx ;shl ax, cl mov result, ax call convert_numbers_to_ascii converter ENDP convert_numbers_to_ascii PROC invoke GetStdHandle, STD_OUTPUT_HANDLE mov outputHandle, eax mov eax,LENGTHOF sum_string invoke WriteConsoleA, outputHandle, addr sum_string, eax, addr bytes_written, 0 mov ax,[result] mov cl,10 mov ebx,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 call main convert_numbers_to_ascii ENDP finish_program PROC invoke ExitProcess, 0 finish_program ENDP END main
Решение задачи: «Преобразователь температуры Masm32»
textual
Листинг программы
adc ah,0 ; ...учитывая перенос.
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д