以判断输入的负数是否在-128到-1范围为例,输入的负数
[BUF+6]不为空则输出EROOR!为空则在[BUF+5]不为空
的前提下,分别取出[BUF+3]、[BUF+4]、[BUF+5]里的
内容(ASCII码)都减去30H,再分别乘100、10、1,求
和与128比较。[BUF+5]为空则直接跳转(在范围内)。
没完全实现:
DATAS SEGMENT
INPUT DB 'Please input a number:$'
OUTPUT1 DB 0AH,0DH,'ERROR!$'
DAT1 DW ?
DAT2 DW ?
DAT3 DW ?
DAT4 DW ?
BUF DB 20
DB ?
DB 20 DUP(?)
OUTPUT2 DB 0AH,0DH,'Y='
YH DB ?
YL DB ?
Z DB '$'
DATAS ENDS
STACKS SEGMENT
DB 200 DUP(?)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
LEA DX,INPUT
MOV AH,9
INT 21H
MOV AH,10
LEA DX,BUF
INT 21H
TEST [BUF+2],0CFH
JZ ABOUTY3
TEST [BUF+2],0D2H
JZ ABOUTY2
JMP ABOUTY1
JMP EXIT
EXIT: MOV AH,4CH
INT 21H
ERROR: LEA DX,OUTPUT1
MOV AH,9
INT 21H
JMP EXIT
ABOUTY1: TEST [BUF+5],0BEH
JNZ ERROR
CMP [BUF+3],'0'
JB ABOUTY11
CMP [BUF+3],'9'
JA ABOUTY11
CMP [BUF+4],'0'
JB ABOUTY11
CMP [BUF+4],'9'
JA ABOUTY11
MOV AL,[BUF+2]
SUB AL,30H
MOV CL,100
MUL CL
MOV DAT1,AX
MOV AX,0
MOV AL,[BUF+3]
SUB AL,30H
MOV CL,10
MUL CL
MOV DAT2,AX
MOV AX,0
MOV BX,DAT1
MOV CX,DAT2
ADD BX,CX
MOV DAT3,BX
MOV AX,0
MOV AL,[BUF+4]
SUB AL,30H
MOV CX,DAT3
ADD AX,CX
MOV DAT4,AX
MOV CX,0
MOV CX,127
MOV AX,DAT4
CMP AX,CX
JNA ABOUTY11
JMP ERROR
JMP EXIT
ABOUTY11: MOV YL,0
MOV YH,31H
LEA DX,OUTPUT2
MOV AH,9
INT 21H
JMP EXIT
ABOUTY2:
CMP [BUF+4],'0'
JB ABOUTY21
CMP [BUF+4],'9'
JA ABOUTY21
CMP [BUF+5],'0'
JB ABOUTY21
CMP [BUF+5],'9'
JA ABOUTY21
MOV AL,[BUF+3]
SUB AL,30H
MOV CL,100
MUL CL
MOV DAT1,AX
MOV AX,0
MOV AL,[BUF+4]
SUB AL,30H
MOV CL,10
MUL CL
MOV DAT2,AX
MOV AX,0
MOV BX,DAT1
MOV CX,DAT2
ADD BX,CX
MOV DAT3,BX
MOV AX,0
MOV AL,[BUF+5]
SUB AL,30H
MOV CX,DAT3
ADD AX,CX
MOV DAT4,AX
MOV CX,0
MOV CX,128
MOV AX,DAT4
CMP AX,CX
JNA ABOUTY21
JMP ERROR
JMP EXIT
ABOUTY21:
MOV YH,2DH
MOV YL,31H
LEA DX,OUTPUT2
MOV AH,9
INT 21H
JMP EXIT
ABOUTY3:
MOV YH,30H
MOV YL,0
LEA DX,OUTPUT2
MOV AH,9
INT 21H
JMP EXIT
CODES ENDS
END START