📄 matrix.asm
字号:
;--------------------------------------------------------------------------------
.model small
;--------------------------------------------------------------------------------
.data ;DATA + VARIABLES
;--------------------------------------------------------------------------------
MessageIntroScreen db 13,10,"This program draws a color character"
db 13,10,"on the Screen and causes it to move."
db 13,10,""
db 13,10,"Press ANY key to exit."
MessageCRLF db 13,10,"$"
varCharacter db 'a'
varColor db 027h
varRowNumber db 5
varColumnNumber db 10
;--------------------------------------------------------------------------------
.stack 100h ;256-word stack;
;--------------------------------------------------------------------------------
.code ; START OF CODE
Program:
;------[ Begin main program body ]-------------------------------------------- call initSegs
call initSegs
mov dx, OFFSET MessageIntroScreen
call printMessage
mov dx, OFFSET MessageCRLF
call printMessage
call Wait4KeyPress
call ClearScreen
main_loop:
call PrintChar
call MoveChar
call ShortDelay
call changeChar
call check4KeyPress
jc main_loop
call eXit
;------[ End main program body ]--------------------------------------------
;------[ Begin PROCedures body ]--------------------------------------------
;------------[ check4KeyPress ]---------------------------------
PROC check4KeyPress
push ax
mov ah, 0Bh
int 21H
cmp al,0 ; is (al == 0) ?
jnz NoKey ;if (al != 0) jump to NoKey label
stc ; else set carry flag
; and return
NoKey:
pop ax
RET
ENDP check4KeyPress
;------------[ ChangeChar ]---------------------------------
Proc changeChar
push dx
mov dl, varColumnNumber
mov dh, varRowNumber
shr dl,2
jnc no_XOR
shr dh,2
jnc no_XOR
xor varColor,08H
no_XOR:
inc VarCharacter
cmp VarCharacter,07 ; BELL
jnz not_Bell
inc VarCharacter ;skip Bell
not_Bell:
pop dx
RET
ENDP ChangeChar
;------------[ initSegs ]--------------------------------
PROC initSegs
mov ax, @DATA
mov ds, ax
mov es,ax
ret
ENDP initSegs
;------------[ printMessage ]---------------------------
PROC printMessage
push ax
mov ah,09h
int 21H
pop ax
ret
ENDP printMessage
;------------[ wait4KeyPress ]---------------------------------
PROC wait4KeyPress
push ax
mov ah, 01h ;Clear Keyb Buffer
int 21h ;call INT 21
pop ax
ret
ENDP wait4KeyPress
;-------------------------[ PrintChar ]--------------------------------------
PROC PrintChar
push ax bx cx dx bp
mov ah,13h ; function 13 - write string (Write Char if length =1!)
mov al,01h ; attrib in bl,move cursor
xor bh,bh ; video page 0
mov bp, OFFSET varCharacter
mov bl, varColor ; attribute 4 - magenta
mov cx,1 ; length of string (character)
mov dh,varRowNumber ; row to put string
mov dl,varColumnNumber ; column to put string
int 10h ; call BIOS service
pop bp dx cx bx ax
ret ; end proc
ENDP PrintChar
;-------------------------[ MoveChar ]--------------------------------------
PROC MoveChar
add varRowNumber, 1
add varColumnNumber, 2
cmp VarRowNumber,23
jna RowOk
mov varRowNumber,1
RowOk:
cmp VarColumnNumber,79
jna ColOK
mov varColumnNumber,0
ColOK:
RET ; end proc
ENDP MoveChar
;-------------------------[ ClearScreen ]--------------------------------------
PROC ClearScreen
push ax bx cx dx
mov bl,0
mov bh,0
sub cx,cx
mov dx,184fh ;18h = 24 rows, 4f = 79 coulums
mov ax,0600h
int 10h
pop dx cx bx ax
RET
ENDP ClearScreen
;-------------------------[ ShortDelay ]--------------------------------------
PROC ShortDelay
push ax bx cx dx ; creates 1 second delay
mov cx,10h
delay0:
push cx
mov cx, 00fffh
delay1:
loop delay1
pop cx
loop delay0
pop dx cx bx ax
RET
ENDP Shortdelay
;------------[ eXit ]-----------------------------------
PROC eXit
push ax
mov ah,4ch ;ah = code to return to DOS
int 21h
pop ax
RET
ENDP eXit
;------------[ END of Procedures Body ]---------------------------
;------[ End main program body ]--------------------------------------------
END Program
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -