汇编与接口结课记录
//纯软件可直接在dosbox编译运行
DATA SEGMENT
GRID DB 100 DUP(20H)
DES DB 0
RB DW 0
TEMP DW ?
TEMP2 DW ?
GAME_STATE DW 1
POS DW ?
FALL DW 0
FFALL DW 0
FIRE DW 0
RAD DW 4H, 7H, 1H, 5H, 2H, 3H
DATA ENDS
STACKS SEGMENT STACK
DW 512 DUP(?)
STACKS ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA, SS:STACKS
MAIN:
MOV AX, DATA
MOV DS, AX
MOV BX, OFFSET GRID
MOV AX, 58
MOV POS, AX
TESTL:
CALL DISPC
NOP
CALL TIME
NOP
CALL INIFOE
NOP
CALL KEYB
NOP
CALL CTR
NOP
CALL CHECK
MOV AH, 0FH
INT 10H
MOV AH,0H
INT 10H
MOV AX, GAME_STATE
CMP AX, 0
JNE TESTL
OVER:
MOV AH, 4CH
INT 21H
DISPC PROC
PUSH BX
PUSH AX
PUSH CX
PUSH SI
PUSH DI
MOV BX, OFFSET GRID
MOV DI, POS
MOV AL, 41H
MOV [BX + DI], AL
MOV AX, FIRE
CMP FIRE, 1
JNE DFIRE
MOV DI, POS
MOV CX, 7
MOV AL, 21H
DFIREL:
MOV [BX + DI], AL
SUB DI, 8
LOOP DFIREL
DFIRE:
MOV DI, 0
MOV SI, 0
MOV CX, 64
DL1:
MOV AL, [BX + DI]
MOV DL, AL
MOV AH, 02H
INT 21H
MOV DL, 20H
INT 21H
INC DI
INC SI
CMP SI, 8
JNE DT1
MOV SI, 0
MOV DL, 0AH
INT 21H
DT1:
LOOP DL1
MOV DI, POS
MOV AL, 20H
MOV [BX + DI], AL
MOV AX, FIRE
CMP AX, 1
JNE DOVER
MOV AX, 0
MOV FIRE, AX
MOV DI, POS
MOV CX, 7
MOV AL, 20H
DL2:
MOV [BX + DI], AL
SUB DI, 8
LOOP DL2
DOVER:
POP DI
POP SI
POP CX
POP AX
POP BX
RET
DISPC ENDP
TIME PROC
PUSH CX
MOV CX, 1
TL1:
PUSH CX
MOV CX, 0FFFFH
TL2:
LOOP TL2
POP CX
LOOP TL1
POP CX
RET
TIME ENDP
CTR PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
PUSH SI
MOV BX, OFFSET GRID
MOV DI, 0
MOV SI, 7
MOV DX, 8
MOV AX, FALL
CMP AX, 20
JNE CTRL3
MOV AX, 0
MOV FALL, AX
CTRL1:
MOV AX, SI
SUB AX, 1
MUL DL
MOV TEMP, DI
ADD DI, AX
SUB AX, AX
MOV AL, [BX + DI]
MOV DI, TEMP
MOV TEMP2, AX
MOV AX, SI
MUL DL
MOV TEMP, DI
ADD DI, AX
MOV AX, TEMP2
MOV [BX + DI], AL
MOV DI, TEMP
INC DI
CMP DI, 8
JNE CTRL1
SUB DI, DI
DEC SI
CMP SI, 0FFFFH
JNE CTRL1
MOV DI, 0
CTRL2:
MOV AX, 20H
MOV [BX + DI], AL
INC DI
CMP DI, 8
JNE CTRL2
CTRL3:
MOV AX, FALL
INC AX
MOV FALL, AX
MOV AL, DES
CMP AL, 1
JE CLEFT
CMP AL, 2
JE CRIGHT
JMP COVER
CLEFT:
MOV AX, POS
DEC AX
CMP AX, 55
JE COVER
MOV POS, AX
JMP COVER
CRIGHT:
MOV AX, POS
INC AX
CMP AX, 64
JE COVER
MOV POS, AX
COVER:
MOV AX, 0
MOV DES, AL
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CTR ENDP
KEYB PROC
PUSH AX
MOV AH, 0BH
INT 21H
CMP AL,00H
JE KOVER
MOV AH, 08H
INT 21H
CMP AL, 6AH
JE KFIRE
CMP AL, 4AH
JE KFIRE
CMP AL, 41H
JE KLEFT
CMP AL, 61H
JE KLEFT
CMP AL, 44H
JE KRIGHT
CMP AL, 64H
JE KRIGHT
JMP KOVER
KFIRE:
MOV AX, 1
MOV FIRE, AX
JMP KOVER
KLEFT:
MOV AX, 1
MOV DES, AL
JMP KOVER
KRIGHT:
MOV AX, 2
MOV DES, AL
KOVER:
POP AX
RET
KEYB ENDP
CHECK PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
PUSH SI
MOV BX, OFFSET GRID
MOV DI, 56
CKL1:
MOV AL, [BX + DI]
CMP AL, 40H
JE CKL2
INC DI
CMP DI, 64
JNE CKL1
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CKL2:
MOV AX, 0
MOV GAME_STATE, AX
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CHECK ENDP
INIFOE PROC
PUSH AX
PUSH BX
PUSH DI
MOV AX, FFALL
CMP FFALL, 30
JNE FOVER
MOV AX, 0
MOV FFALL, AX
MOV AX, RB
CMP AX, 5
JNE FOET1
MOV AX, 0
MOV RB, AX
FOET1:
MOV BX, OFFSET RAD
MOV AX, RB
MOV DI, AX
MOV AX, [BX + DI]
MOV BX, OFFSET GRID
MOV DI, AX
MOV AL, 40H
MOV [BX + DI], AL
MOV AX,RB
INC AX
MOV RB, AX
FOVER:
MOV AX, FFALL
INC AX
MOV FFALL, AX
POP DI
POP BX
POP AX
RET
INIFOE ENDP
CODE ENDS
END MAIN
//软硬结合(清华实验箱)
DATA SEGMENT
GRID DB 100 DUP(20H)
DES DB 0
RB DW 0
TEMP DW ?
TEMP2 DW ?
OLD_OFFSET DW ?
OLD_SEG DW ?
R DW ?
C DW ?
ROW DB ?
COL DB ?
GAME_STATE DW 1
POS DW ?
FALL DW 0
FFALL DW 0
FIRE DW 0
RAD DW 4H, 7H, 1H, 5H, 2H, 3H
DATA ENDS
STACKS SEGMENT STACK
DW 1024 DUP(?)
STACKS ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA, SS:STACKS
MAIN:
MOV BX, 4 * 0BH
MOV AX, 0
MOV DS, AX
MOV AX, [BX]
MOV OLD_OFFSET, AX
MOV AX, [BX + 2]
MOV OLD_SEG, AX
MOV AX, OFFSET MYINT
MOV [BX], AX
MOV AX, SEG MYINT
MOV [BX + 2], AX
MOV AX, DATA
MOV DS, AX
MOV DX, 293H
MOV AL, 10010000B
OUT DX, AL
MOV AX, 0
MOV ROW, AL
MOV COL, AL
MOV BX, OFFSET GRID
MOV AX, 58
MOV POS, AX
TESTL:
CALL DISPC
CALL TIME
CALL INIFOE
CALL KEYB
CALL CTR
CALL CHECK
MOV AX, GAME_STATE
CMP AX, 0
JNE TESTL
OVER:
MOV AX, 0
MOV DS, AX
MOV BX, 4 * 0BH
MOV AX, OLD_OFFSET
MOV [BX], AX
MOV AX, OLD_SEG
MOV [BX + 2], AX
MOV AH, 4CH
INT 21H
DISPC PROC
PUSH DX
PUSH BX
PUSH AX
PUSH CX
PUSH SI
PUSH DI
MOV BX, OFFSET GRID
MOV DI, POS
MOV AL, 41H
MOV [BX + DI], AL
MOV AX, FIRE
CMP FIRE, 1
JNE DFIRE
MOV DI, POS
MOV CX, 7
MOV AL, 21H
DFIREL:
MOV [BX + DI], AL
SUB DI, 8
LOOP DFIREL
DFIRE:
MOV BX, OFFSET GRID
MOV AX, 0
MOV R, AX
MOV C, AX
MOV COL, AL
MOV AL, 1
MOV ROW, AL
DDT1:
MOV DI, C
MOV AX, R
SUB DL, DL
MOV DL, 08H
MUL DL
ADD DI, AX
MOV DL, [BX + DI]
MOV AL, COL
CMP DL, 20H
JE DDT2
OR AL, 00000001B
DDT2:
SHL AL, 1
MOV COL, AL
MOV DI, C
INC DI
MOV C, DI
CMP DI, 0008H
JNE DDT1
MOV AL, COL
SHR AX, 1
MOV COL, AL
SUB DI, DI
MOV C, DI
MOV AL, ROW
MOV DX, 280H
OUT DX, AL
SHL AX, 1
MOV ROW, AL
MOV DX, 288H
MOV AL, COL
OUT DX, AL
MOV SI, R
INC SI
MOV R, SI
CMP SI, 0008H
JNE DDT1
MOV DI, POS
MOV AL, 20H
MOV [BX + DI], AL
MOV AX, FIRE
CMP AX, 1
JNE DOVER
MOV AX, 0
MOV FIRE, AX
MOV DI, POS
MOV CX, 7
MOV AL, 20H
DL2:
MOV [BX + DI], AL
SUB DI, 8
LOOP DL2
DOVER:
POP DI
POP SI
POP CX
POP AX
POP BX
POP DX
RET
DISPC ENDP
TIME PROC
PUSH CX
MOV CX, 20
TL1:
PUSH CX
MOV CX, 0FFFFH
TL2:
LOOP TL2
POP CX
LOOP TL1
POP CX
RET
TIME ENDP
CTR PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
PUSH SI
MOV BX, OFFSET GRID
MOV DI, 0
MOV SI, 7
MOV DX, 8
MOV AX, FALL
CMP AX, 20
JNE CTRL3
MOV AX, 0
MOV FALL, AX
CTRL1:
MOV AX, SI
SUB AX, 1
MUL DL
MOV TEMP, DI
ADD DI, AX
SUB AX, AX
MOV AL, [BX + DI]
MOV DI, TEMP
MOV TEMP2, AX
MOV AX, SI
MUL DL
MOV TEMP, DI
ADD DI, AX
MOV AX, TEMP2
MOV [BX + DI], AL
MOV DI, TEMP
INC DI
CMP DI, 8
JNE CTRL1
SUB DI, DI
DEC SI
CMP SI, 0FFFFH
JNE CTRL1
MOV DI, 0
CTRL2:
MOV AX, 20H
MOV [BX + DI], AL
INC DI
CMP DI, 8
JNE CTRL2
CTRL3:
MOV AX, FALL
INC AX
MOV FALL, AX
MOV AL, DES
CMP AL, 1
JE CLEFT
CMP AL, 2
JE CRIGHT
JMP COVER
CLEFT:
MOV AX, POS
DEC AX
CMP AX, 55
JE COVER
MOV POS, AX
JMP COVER
CRIGHT:
MOV AX, POS
INC AX
CMP AX, 64
JE COVER
MOV POS, AX
COVER:
MOV AX, 0
MOV DES, AL
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CTR ENDP
KEYB PROC
PUSH AX
PUSH DX
MOV DX, 290H
IN AL, DX
MOV DL, AL
AND AL, 00000001B
CMP AL, 1
JNE KB1
MOV AL, 2
MOV DES, AL
JMP KB2
KB1:
MOV AL, 1
MOV DES, AL
KB2:
MOV AL, DL
AND AL, 00000010B
CMP AL, 0
JE KBOVER
MOV AX, 1
MOV FIRE, AX
KBOVER:
POP DX
POP AX
RET
KEYB ENDP
CHECK PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
PUSH SI
MOV BX, OFFSET GRID
MOV DI, 56
CKL1:
MOV AL, [BX + DI]
CMP AL, 40H
JE CKL2
INC DI
CMP DI, 64
JNE CKL1
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CKL2:
MOV AX, 0
MOV GAME_STATE, AX
MOV DX, 293H
MOV AX, 10000000B
OUT DX, AL
MOV DX, 290H
MOV AL, 11111111B
OUT DX, AL
MOV DX, 2A3H
MOV AL, 00110110B
OUT DX, AL
MOV AX, 394H
MOV DX, 2A0H
OUT DX, AL
MOV CL, 4
SHR AX, CL
OUT DX, AL
MOV CX, 20
CCOVER:
CALL TIME
LOOP CCOVER
MOV DX, 290H
MOV AL, 00000000B
OUT DX, AL
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
RET
CHECK ENDP
INIFOE PROC
PUSH AX
PUSH BX
PUSH DI
MOV AX, DATA
MOV DS, AX
MOV AX, FFALL
CMP FFALL, 30
JNE FOVER
MOV AX, 0
MOV FFALL, AX
MOV AX, RB
CMP AX, 5
JNE FOET1
MOV AX, 0
MOV RB, AX
FOET1:
MOV BX, OFFSET RAD
MOV AX, RB
MOV DI, AX
MOV AX, [BX + DI]
MOV BX, OFFSET GRID
MOV DI, AX
MOV AL, 40H
MOV [BX + DI], AL
MOV AX,RB
INC AX
MOV RB, AX
FOVER:
MOV AX, FFALL
INC AX
MOV FFALL, AX
POP DI
POP BX
POP AX
RET
INIFOE ENDP
MYINT PROC
PUSH AX
MOV AX, 1
MOV FIRE, AX
POP AX
RET
MYINT ENDP
CODE ENDS
END MAIN