assembly - 使用 MASM 汇编器将华氏度转换为摄氏度

标签 assembly masm low-level

我正在学习如何编写低级语言,我正在尝试编写一个程序,从用户那里获取华氏度,然后通过此操作将其转换为摄氏度

( 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/

相关文章:

linux - 尝试在 Linux 上打开文件时,MARS MIPS 模拟器卡住

c - gcc 内在与内联汇编 : which is better?

c - 指针和数组之间的效率(更少的汇编指令不会花费更少的时间)

c - 多个线程调用同一个 rand() 函数,如何让它们调用自己的 rand() 函数实例?

C、写系统调用,写int

c - 编译 ld86 时出现问题 : Undefined symbol auto_start

assembly - FLAT 操作数对 SEGMENT 指令的影响?

c++ - 我如何获得另一个柜台?

assembly - 设置溢出标志的说明

performance - 异或链表的目的?