⑴ 用匯編語言 從鍵盤輸入一個有符號數,判斷其正負,若為負數,在屏幕上顯
;從鍵盤輸入一個有符號數,判斷其正負,
;若為負數,在屏幕上顯示「-」號,
;若為正數,則在屏幕上顯示「+」號;若為0,則顯示「0」,
;若輸入的數據不是一個完整的有符號數,則顯示「input
error」;
ASSUME
CS:CC,
DS:QQ
QQ
SEGMENT
MSR
DB
13,
10,
'Please
input
data:
$'
MSD1
DB
13,
10,
'The
result
is:
$'
MSD2
DB
13,
10,
'Input
error.
$'
MAX
DB
10
;計劃輸入的字元個數(含回車符)
NNN
DB
0
;存放實際輸入的字元個數
BUF
DB
10
DUP(?)
FUH
DB
'+'
QQ
ENDS
CC
SEGMENT
START:
MOV
AX,
QQ
MOV
DS,
AX
MOV
AH,
09H
;顯示提示信息PLEASE
INPUT
DATA:
MOV
DX,
OFFSET
MSR
INT
21H
MOV
AH,
0AH
;從鍵盤輸入數據
MOV
DX,
OFFSET
MAX
INT
21H
MOV
CL,
NNN
CMP
CL,
0
JZ
EXIT
MOV
CH,
0
MOV
BX,
0
LEA
SI,
BUF
MOV
AL,
[SI]
CMP
AL,
'+'
JZ
FU_HAO
CMP
AL,
'-'
JZ
FU_HAO
CMP
AL,
'0'
JB
NO
CMP
AL,
'9'
JA
NO
CMP
AL,
'0'
JZ
NEXT
INC
BX
JMP
NEXT
SSS:
MOV
AL,
[SI]
CMP
AL,
'0'
JB
NO
CMP
AL,
'9'
JA
NO
CMP
AL,
'0'
JZ
NEXT
INC
BX
NEXT:
INC
SI
LOOP
SSS
JMP
DISP
FU_HAO:
MOV
FUH,
AL
JMP
NEXT
DISP:
CMP
BX,
0
JNZ
ZH_FU
MOV
FUH,
'0'
ZH_FU:
MOV
AH,
09H
;顯示提示信息THE
RESULT
IS:
MOV
DX,
OFFSET
MSD1
INT
21H
MOV
DL,
FUH
MOV
AH,
02H
INT
21H
JMP
EXIT
NO:
MOV
AH,
09H
;顯示提示信息
MOV
DX,
OFFSET
MSD2
INT
21H
EXIT:
MOV
AH,
4CH
;返回DOS狀態,固定結構
INT
21H
CC
ENDS
END
START