该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
ASSUME CS:CC, DS:QWER
QWER SEGMENT
MSG1 DB 13, 10, 'This program can generate a clockwise spiral matrix of order N.'
DB 13, 10, 'If you type 4, the matrix of order 4 will appear : '
CRLF DB 13, 10, 36
MSG2 DB 13, 10, 'Please input a number(1~9): $'
MSG3 DB 13,10,'1','$'
MSG9 DB 13, 10, 13, 10, 'Press any key to continue...$', 36
BUF DB 15 * 15 DUP(?)
HH DB 8
BUF3 DB 1, 2, 3, 4, 12,13,14, 5, 11,16,15, 6, 10, 9, 8, 7
HH3 DB 4
NN DB 1
DIR_X DB 1
DIR_H DB 1
DIR_L DB 1
N_H DB ?
N_L DB ?
N_H2 DB ?
N_L2 DB ?
QWER ENDS
CC SEGMENT
START:
MOV AX, QWER
MOV DS, AX
LEA DX, MSG1
MOV AH, 9
INT 21H
CALL CR_LF
MOV SI, OFFSET BUF3
MOV CH, HH3
CALL DISP_MATRIX
ReRun:
call init
LEA DX, MSG2
MOV AH, 9
INT 21H
MOV HH, 0
MOV CX, 2
IN_X:
MOV AH, 7
INT 21H
CMP AL,1BH
JNZ goNext
JMP EXIT
goNext:
CMP AL, 13
JZ IN_END
CMP AL, '0'
JB IN_X
CMP AL, '9'
JA IN_X
MOV DL, AL
MOV AH, 2
INT 21H
MOV AL, DL
AND AL, 15
XCHG AL, HH
MOV BL, 10
MUL BL
ADD HH, AL
LOOP IN_X
IN_END:
CMP HH, 1
JA @F
JB EXIT
LEA DX,MSG3
MOV AH,9
INT 21H
JMP ReRun
@@:
CMP HH, 9
JA EXIT
CALL CR_LF
CALL CR_LF
MOV AL, HH
MOV N_H, AL
DEC AL
MOV N_H2, AL
MOV N_L, AL
MOV N_L2, AL
MOV BX, 0
MOV DI, 0
MOV NN, 1
LOOPS:
MOV AL, NN
MOV BUF[BX][DI], AL
TEST DIR_X, 1
JZ LX
CALL HH_HH
JMP NEXT
LX:
CALL LL_LL
NEXT:
INC NN
MOV AL, HH
MUL HH
CMP AL, NN
JNC LOOPS
MOV SI, OFFSET BUF
MOV CH, HH
CALL DISP_MATRIX
jmp ReRun
EXIT:
MOV AX, 4C00H
INT 21H
HH_HH:
TEST DIR_H, 1
JZ HH_SUB1
HH_ADD1:
INC BX
JMP HH_NEXT
HH_SUB1:
DEC BX
HH_NEXT:
DEC N_H2
CMP N_H2, 0
JNZ E_HH
DEC N_H
MOV AL, N_H
MOV N_H2, AL
INC DIR_H
INC DIR_X
E_HH:
RET
LL_LL:
TEST DIR_L, 1
JZ LL_SUB1
LL_ADD1:
MOV AL, HH
MOV AH, 0
ADD DI, AX
JMP LL_NEXT
LL_SUB1:
MOV AL, HH
MOV AH, 0
SUB DI, AX
LL_NEXT:
DEC N_L2
CMP N_L2, 0
JNZ E_LL
DEC N_L
MOV AL, N_L
MOV N_L2, AL
INC DIR_L
INC DIR_X
E_LL:
RET
DISP_MATRIX:
MOV NN, CH
DP0