calc.asm
来自「介绍用Java解析网络数据的三种特殊方法」· 汇编 代码 · 共 87 行
ASM
87 行
; This sample gets two numbers
; from the user, calculates the
; sum of these numbers,
; and prints it out.
#make_COM#
include 'emu8086.inc'
ORG 100h
; skip variable declaration:
JMP START
; declaration of variable:
num DW ?
START:
; get first number:
CALL PTHIS
DB 13, 10, 'Calculation Range: [-32768..32767]', 13, 10
DB 13, 10, 'Enter first number: ', 0
CALL scan_num
; keep first number:
MOV num, CX
; get second number:
CALL PTHIS
msg2 DB 13, 10, 'Enter second number: ', 0
CALL scan_num
; add numbers:
ADD num, CX
JO overflow
; print the result:
CALL PTHIS
DB 13, 10, 'The sum is: ', 0
MOV AX, num
CALL print_num
JMP exit
; process overlow error:
overflow:
PRINTN 'We have overflow!'
exit:
RET
;=================================
; here we define the functions
; from emu8086.inc
; SCAN_NUM reads a
; number from the user and stores
; it in CX register.
DEFINE_SCAN_NUM
; PRINT_NUM prints a signed
; number in AX.
; PRINT_NUM_UNS prints an unsigned
; number in AX (required by
; PRINT_NUM):
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
; PTHIS prints NULL terminated
; string defined just after
; the CALL PTHIS instruction:
DEFINE_PTHIS
;=================================
END
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?