DATA SEGMENT
TABLE DB 00H,01H,04H,09H,16H,25H,36H,49H,64H,81H
RSLT DB ?
STRING DB 'please enter a number:','$'
STRING1 DB 0DH,0AH,'the result is:$'
DATA ENDS
STACK SEGMENT STACK
DB 100 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA DX,STRING
MOV AH,09H
INT 21H
MOV AH,01H ;接受一個字符,並回顯
INT 21H ;注意:如果是mov ah,00h 則是int 16h
AND AL, 0FH
XOR BX, BX;清零
MOV BL, AL
LEA SI, TABLE
MOV AL, [SI+BX];輸入一個數
MOV RSLT, AL
LEA DX,STRING1
MOV AH,09H
INT 21H
MOV DL,RSLT
CMP DL,9
JG NEXT1
JNG NEXT2
NEXT1:
MOV BL,DL
MOV CL,4
SHR DL,CL
ADD DL,30H
CALL NEXT3
MOV DL,BL
AND DL,0FH
ADD DL,30H
CALL NEXT3
MOV AH, 4CH
INT 21H
NEXT2:
ADD DL,30H
CALL NEXT3
MOV AH, 4CH
INT 21H
NEXT3:
MOV AH,02H
INT 21H
RET
MOV AH, 4CH
INT 21H
CODE ENDS
END START
跳轉指令的問題,把條件跳轉改為ja(大於),jna(不大於)。