我正在学习如何编写低级语言,我正在尝试编写一个程序,从用户那里获取华氏度,然后通过此操作将其转换为摄氏度
( 5/9 ) * (input- 32)
为了得到结果,我首先计算
5*(input - 32)
将乘积留在ax
中,然后除以9,但随后我得到了错误的结果。
感谢您的帮助。
include PCMAC.INC
.model small
.586
.stack 100h
.data
msg db 'Enter the degree in fahrenheit: $'
input dw ?
cel dw ?
outputmsg db " Conversion done, result is $"
outputmsg2 db " celsius", 13, 10, '$'
A dw 5
B dw 9
.code
extrn GetDec:near, PutDec:near
main PROC
_Begin
_Putstr msg
call GetDec
mov input, ax
mov bl, 32
sub al, bl
; sub ax, 32
mov cx, A
imul cx
mov cx, B
idiv cx
mov cel, ax
_putstr outputmsg
call PutDec
_putstr outputmsg2
_Exit 0
main endp
end main
我刚刚编辑了代码,现在当摄氏度为正时我得到了正确的答案,但是当我的答案(摄氏度)为负时结果是错误的我不知道如何获得负摄氏度
最佳答案
Mov cx, [B]
Imul cx
Mov cx, [A]
Idiv cx
当对此类事情有疑问时,请再次反汇编您的代码。我清楚地记得 imul 和 idiv 在使用 masm 时不喜欢非注册参数
另外,总是放 ?非之后? dw 值。否则,疯狂的不可能的错误。
关于assembly - 使用 MASM 汇编器将华氏度转换为摄氏度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52920432/