DISP_STR MACRO X ;宏定义.
MOV DX, OFFSET X
MOV AH, 9 ;输出字符串
INT 21H
ENDM
;----------------------------------------------
DATA SEGMENT ;数据段.
MSG1 DB 13, 10, 'Input N
MSG2 DB 13, 10, 'I can not count so much !
MSG3 DB 13, 10, 'Please Input NUM (1~9, 0 end):
MSG4 DB 13, 10, 'Please Input Matrix from 0~15,remember to have a space between each data!!!
MSG5 DB 13, 10, 'The sum of leading diagonal is :
MSG6 DB 13, 10, 'Reprint the matrix:
IN_N1 DB 16 DUP ('$$) ;影响
ONLY DB 0
SUM DD 0
N DB 30H ;序数.
DATA ENDS
;----------------------------------------------
CODE SEGMENT ;代码段.
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
;--------------------------------
MOV BX, OFFSET IN_N1;数据
MOV CX, 16 ;循环次数
;--------------------------------
DISP_STR MSG4
CALL INPUT
;==========================================================
LEA SI,IN_N1
LEA DI,SUM
mov ax,[SI] ;1
add [DI],ax
mov ax,[SI+2]
adc [DI+2],ax
JC SS1 ;如果进位 跳转到SS1
B1:
ADD SI,25 ;6
mov ax,[SI]
add [DI],ax
mov ax,[SI+2]
adc [DI+2],ax
JC SS2
B2:
ADD SI,25 ;11
mov ax,[SI]
add [DI],ax
mov ax,[SI+2]
adc [DI+2],ax
JC SS3
B3:
ADD SI,25 ;16
mov ax,[SI]
add [DI],ax
mov ax,[SI+2]
adc [DI+2],ax
JC SS4
JMP IN_END
SS1:
INC ONLY
JMP B1
SS2:
INC ONLY
JMP B2
SS3:
INC ONLY
JMP B3
SS4:
INC ONLY
;=============================
IN_END:
DISP_STR MSG5
MOV DL,ONLY
ADD DL,30H
MOV AH, 2
INT 21H
LEA SI,SUM
MOV DL,[SI]
ADD DL,30H
MOV AH, 2
INT 21H
MOV DL,[SI+1]
ADD DL,30H
MOV AH, 2
INT 21H
MOV DL,[SI+2]
ADD DL,30H
MOV AH, 2
INT 21H
MOV DL,[SI+3]
ADD DL,30H
MOV AH, 2
INT 21H
MOV DL, 13 ;换行
MOV AH, 2
INT 21H
MOV DL,10
MOV AH, 2
INT 21H
;=========================================
DISP_STR MSG6;未施工完成
JMP EXIT
;--------------------------------
_IN_ERR:
DISP_STR MSG2 ;宏调用,提示 can not count so much !
EXIT:
MOV AH, 4CH
INT 21H
;--------------------------------------------
INPUT: ;所有输入过程
IN_X:
PUSH CX
DISP_STR MSG1 ;宏调用,提示 Please Input :
INC N
;MOV DL, N
;MOV AH, 2
;INT 21H
MOV DL, ':'
MOV AH, 2
INT 21H
MOV DX, BX
IN_LOOP:
MOV AH, 1 ;输入字符.
INT 21H
CMP AL, ' ' ;空格?
JZ IN_Y ;本数字结束.
CMP AL, 30H
JB _IN_ERR ;小于'0',输入错误.
CMP AL, 3AH
JNB _IN_ERR ;大于'9',输入错误.
SUB AL,30H;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MOV [BX], AL
INC BX
MOV AX, BX
SUB AX, 3 ;影响
SUB AX, DX
JA IN_Y
JMP IN_LOOP ;继续输入.
IN_Y:
ADD DX, 5 ;影响
MOV BX, DX
POP CX
LOOP IN_X
RET
;--------------------------------
CODE ENDS
END START