fahrenheit.asm

来自「介绍用Java解析网络数据的三种特殊方法」· 汇编 代码 · 共 59 行

ASM
59
字号

; Centigrade (Celsius) to Fahrenheit
; calculation and vice-versa.
; (not very accurate, since using
; integer divide, it may not work
; for some values as well...).

; This program has no input/output from
; the user, so in order to see the result
; it maybe useful to select "Variables"
; from "View" menu of the emulator.

; Another way to see the output is to
; use PRINT_NUM procedure from "emu8086.inc",
; see "Part 5" in tutorials.
; (since we get result in AL, you should use
; CBW instruction before printing out,
; because PRINT_NUM prints a signed number
; in AX register).

#MAKE_COM#


ORG 100h

JMP start

tc DB 10    ; t Celsius.
tf DB 0     ; t Fahrenheit.

result1 DB ?   ; result in Fahrenheit.
result2 DB ?   ; result in Celsius.

start:

; convert Celsius to Fahrenheit according
; to this formula: f = c * 9 / 5 + 32

MOV CL, tc
MOV AL, 9
IMUL CL
MOV CL, 5
IDIV CL
ADD AL, 32
MOV result1, AL

; convert Fahrenheit to Celsius according
; to this formula: c = (f - 32) * 5 / 9

MOV CL, tf
SUB CL, 32
MOV AL, 5
IMUL CL
MOV CL, 9
IDIV CL
MOV result2, AL

RET

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?