user-0 提问: 有趣的汇编程序

回复:
user: user-1
content: http://84.15.64.35/#newwindow=1&q=%E6%B1%87%E7%BC%96%E7%A8%8B%E5%BA%8F%E7%BB%83%E6%89%8B

user: user-2
content: 建议楼主移驾汇编论坛。

user: user-2
content: 纯DOS下试试这个？ CODE   SEGMENT     'CODE'        ASSUME     CS:CODE, DS:CODE, ES:CODE, SS:CODE EndFlag    DB      0 Int9Enter  PROC   FAR 	STI 	PUSH	BP 	PUSH	AX 	PUSH	BX 	PUSH	CX 	PUSH	DX 	PUSH	SI 	PUSH	DI 	PUSH	DS 	PUSH	ES 	PUSH	CS 	POP	ES 	CLD         MOV	AX,	0F000h         MOV	DS,	AX         MOV	SI,	0FFFEH         CMP	BYTE PTR [SI], 0FCH	;PC/AT? 	PUSH	CS 	POP	DS         JNZ	$PCXT1         MOV	CS:BYTE PTR PCAT,  01         MOV	AL,	0ADH                       ;Select 8042 for Scan-Code         CALL SetKey         CLI	         XOR	CX,	CX     $J1:         IN	AL,	64H                       ;Test 8042 Ready?         LOOPNZ   $J1         IN	AL,	60H 		;Get  Scan-Code         STI	         CMP	AL,	0FEH         JZ	$J2		     	;Jmp To Control Char         CMP	AL,	0FAH         JNZ	$J3 $J2:	JMP	$Exit1 ;    $PCXT1: 	IN	AL,60H		;Get PC/XT Scan-Code     $J3: 	;D7=0  - Down    1  - Up 	CMP	AL,1	;[ESC] KEY 	JZ	$End 	CALL	ShowCode 	CALL	Music 	JMP	$Exit1 $End:	MOV	BYTE PTR CS:EndFlag,-1	 ;    $Exit1: 	CALL	AllowKey 	POP	ES 	POP	DS 	POP	DI 	POP	SI 	POP	DX 	POP	CX 	POP	BX 	POP	AX 	POP	BP 	CLI 	IRET ; PCAT	  DB	0		;0 - PC/XT   1 - PC/AT HEX    DB '0123456789ABCDEF' Int9Enter ENDP ; ; SetKey  PROC	NEAR 	PUSH	AX 	CLI	 	SUB	CX,	CX   $SET: 	IN	AL,	64H 	TEST	AL,	02 	LOOPNZ	$SET 	POP	AX 	OUT	64H,	AL 	STI	 	RET	 SetKey   ENDP ; ; AllowKey PROC	NEAR 	CLI	 	MOV	AL,	20H 	OUT	20H,	AL 	CMP	CS:BYTE PTR PCAT,00 	JZ	$PCXT2 	MOV	AL,	0AEH 	CALL	SetKey 	RET ;    $PCXT2: 	IN	AL,	61H 	MOV	AH,	AL 	OR	AL,	80H 	OUT	61H,	AL 	XCHG	AH,	AL 	OUT	61H,	AL 	RET AllowKey ENDP ; ShowCode	PROC 	PUSH	AX 	PUSH	AX 	MOV	CL,4 	SHR	AL,CL 	XOR	BH,BH 	MOV	BL,AL 	MOV	AL,CS:HEX[BX] 	MOV	AH,0EH 	INT	10H 	POP	AX 	AND	AL,0FH 	XOR	BH,BH 	MOV	BL,AL 	MOV	AL,CS:HEX[BX] 	MOV	AH,0EH 	INT	10H 	MOV	AX,0E08H 	INT	10H 	MOV	AX,0E08H 	INT	10H 	POP	AX 	RET ShowCode	ENDP ; Music	PROC	NEAR 	XOR	AH,AH 	CMP	AL,_AL 	JNE	$NEW 	JMP	Loc_84 $NEW:	MOV	_AL,AL 	TEST	AL,80H 	JNZ	$Up 	CALL	KeyPush 	MOV	BX,AX 	MOV	KeyDownTbl[BX],-1 ; $Down:	SHL	AX,1 	MOV	BX,AX 	MOV	AX,OFFSET CS:ToneTbl 	ADD	BX,AX 	MOV	CX,OFFSET CS:ToneTbl 	CMP	BX,CX 	JGE	Loc_79 Loc_78: 	MOV	BX,TblLen-2 	ADD	BX,AX 	JMP	Loc_80 Loc_79: 	MOV	CX,TblLen-4 	ADD	CX,AX 	CMP	BX,CX 	JG	Loc_78 Loc_80: 	MOV	AL,0B6H 	OUT	43H,AL		; port 43H, 8253 wrt timr mode 	MOV	AX,2870H 	MOV	DX,12H 	DIV	WORD PTR CS:[BX] 	OUT	42H,AL		; port 42H, 8253 timer 2 spkr 	MOV	AL,AH 	OUT	42H,AL		; port 42H, 8253 timer 2 spkr 	IN	AL,61H		; port 61H, 8255 port B, read 	OR	AL,3 	OUT	61H,AL		; port 61H, 8255 B - spkr, etc 	JMP	Loc_84 ; $Up:	AND	AL,7FH 	MOV	BX,AX 	MOV	KeyDownTbl[BX],0 Loc_81:	CALL	KeyPop 	CMP	SI,OFFSET KeyStack-1 	JE	$Off 	MOV	BX,AX 	CMP	KeyDownTbl[BX],0 	JE	Loc_81 	CALL	KeyPush 	JMP	$Down $Off:	INC	KeySP 	IN	AL,61H		; port 61H, 8255 port B, read 	AND	AL,0FCH 	OUT	61H,AL		; port 61H, 8255 B - spkr, etc Loc_84: 	MOV	CX,8 LocLoop_85: 	LOOP	LocLoop_85 	RET ; ToneTbl	DB	42H, 0, 45H, 0, 4AH, 0 	DB	4EH, 0, 53H, 0, 57H, 0 	DB	5DH, 0, 62H, 0, 68H, 0 	DB	6EH, 0, 75H, 0, 7CH, 0 	DB	83H, 0, 8BH, 0, 93H, 0 	DB	9EH, 0, 0A5H, 0, 0AFH, 0 	DB	0B9H, 0, 0C4H, 0, 0D0H, 0 	DB	0DCH, 0, 0E9H, 0, 0F7H, 0 	DB	6, 1, 16H, 1, 26H, 1 	DB	38H, 1, 4AH, 1, 5EH, 1 	DB	73H, 1, 88H, 1, 9FH, 1 	DB	0B8H, 1, 0D2H, 1, 0EEH, 1 	DB	0BH, 2, 2AH, 2, 4BH, 2 	DB	6EH, 2, 93H, 2, 0BAH, 2 	DB	0E4H, 2, 10H, 3, 3EH, 3 	DB	70H, 3, 0A5H, 3, 0DCH, 3 	DB	18H, 4, 56H, 4, 98H, 4 	DB	0F0H, 4, 28H, 5, 76H, 5 	DB	0CAH, 5, 22H, 6, 80H, 6 	DB	0E3H, 6, 4BH, 7, 0BAH, 7 TblLen	EQU	$-ToneTbl KeyDownTbl	DB	80H DUP(0) KeyStack	DB 100 DUP(?) KeySP	DW	KeyStack _AL	DB	0 Music	ENDP ; KeyPush	PROC 	MOV	SI,KeySP 	MOV	BYTE PTR [SI],AL 	INC	SI 	MOV	KeySP,SI 	RET KeyPush	ENDP KeyPop	PROC 	MOV	SI,KeySP 	DEC	SI 	MOV	AL,BYTE PTR [SI] 	MOV	KeySP,SI 	RET KeyPop	ENDP ; ; START	PROC 	PUSH	CS 	POP	DS 	MOV	AX,3509H 	INT	21H 	MOV	AX,ES 	MOV	WORD PTR OldInt9+2,AX 	MOV	WORD PTR OldInt9,BX 	MOV	AX,2509H 	MOV	DX,OFFSET Int9Enter 	INT	21H ; WaitINT9: 	CMP	BYTE PTR CS:EndFlag,0 	NOP 	JZ	WaitINT9 ; Quit:	MOV	DX,WORD PTR OldInt9 	MOV	AX,WORD PTR OldInt9+2 	MOV	DS,AX 	MOV	AX,2509H 	INT	21H 	MOV	AX,4C00H 	INT	21H OldInt9	DD	? START	ENDP ; CODE	ENDS 	END	START

user: user-3
content: 之前看有人用汇编写过贪食蛇，你可以试一下

user: user-4
content: 自己写个程序，运行，反汇编

user: user-0
content: 恩恩，谢谢赵4老师