📄 macro.asm
字号:
TRUE EQU 1
FALSE EQU 0
OpenWin macro x1,y1,x2,y2,attr ;开窗口,[开始点(x1,y1),结束点(x2,y2),属性attr]
mov ax,0600h
mov bh,attr
mov cl,x1
mov ch,y1
mov dl,x2
mov dh,y2
int 10h
endm
GotoXY macro x,y ;置光标位置,[点(x,y)]
mov ah,02h
mov bh,0
mov dl,x
mov dh,y
int 10h
endm
ShowChar macro char,attr ;显示字符(光标前移),[字符char,属性attr]
mov al,char
mov bl,attr
mov ah,0eh
int 10h
endm
ShowChar_DOS macro char ;显示字符(光标前移),[字符char]
mov ah,02h
mov dl,char
int 21h
endm
MulShowCharA macro char,attr,reptimes ;在光标位置重复以其属性显示字符,[字符char,属性attr,重复次数reptimes]
mov ah,09h
mov al,char
mov bl,attr
mov bh,0
mov cx,reptimes
int 10h
endm
MulShowChar macro char,reptimes ;在光标位置重复以默认属性显示字符,[字符char,重复次数reptimes]
mov ah,0ah
mov al,char
mov cx,reptimes
mov bh,0
int 10h
endm
ShowString_BIOS macro length,x,y,attr ;显示字符串(调用前先将串地址赋给bp),[字符串长度length,开始点(x,y),属性attr]
mov cx,length
mov dl,x
mov dh,y
mov bh,0
mov bl,attr
mov ax,1301h
int 10h
endm
ShowString_BIOSA macro buffer,length,x,y
mov bp,offset buffer
mov ax,1303h
mov bh,0
mov cx,length
mov dl,x
mov dh,y
int 10h
endm
ShowString_DOS macro buffer,x,y ;显示字符串,[串地址buffer,开始点(x,y)]
push dx
GotoXY x,y
mov ah,09h
mov dx,offset buffer
int 21h
pop dx
endm
ShowString_DOSNB macro x,y ;显示字符串,[串地址buffer,开始点(x,y)]
push dx
push bp
GotoXY x,y
pop dx
mov ah,09h
int 21h
pop dx
endm
Div3 macro ;除3指令
xor ax,ax
mov al,_CurX
mov bl,3
div bl
endm
DivCySe macro cyseH,cyseL,cylin,sect
push ax
push cx
mov ah,cyseH
and ah,3fh
mov sect,ah
mov ah,cyseH
mov cl,6
shr ah,cl
mov al,cysel
mov cylin,ax
pop cx
pop ax
endm
Int13 macro cmd,buffer ;调用中断13功能,[功能号cmd,数据缓冲区地址buffer]
mov ah,cmd
mov al,1
mov bx,offset buffer
mov ch,byte ptr _CurCylin
mov dh,byte ptr _CurHead
mov cl,byte ptr _CurSector
mov dl,_CurDisk
int 13h
endm
EInt13 macro cmd,buffer ;调用扩展中断13功能,[功能号cmd,数据缓冲区地址buffer]
push si
mov DapOffset,offset buffer
mov DapSegment,seg buffer
mov ah,cmd
mov dl,_CurDisk
mov si,offset dap
int 13h
pop si
endm
ClearArr macro array,length
push di
mov di,offset array
xor ax,ax
mov cx,length
rep stosw
pop di
endm
Hex2Bcd macro hexh,hexl,array,startoffset,length ;十六进制数转为十进制数并存入数组,[十六进制数高字hexh,十六进制数低字hexl,存入数组array,存入数组开始偏移startoffset,十进制数最大长度length]
local lpdiv,lpzero,exit
push di
mov ax,hexl
mov dx,hexh
mov di,offset array
add di,startoffset
mov cx,length
lpdiv: push cx ;这里采用了编写的扩展除法,在09ff ffffh(167772159)以内除以10均不会产生溢出
mov cx,10
push bx
xor bx,bx
push ax
mov ax,dx
div cl
mov bl,al
mov dl,ah
mov dh,0
pop ax
div cx
mov cx,dx
mov dx,bx
pop bx
or cl,30h
mov [di],cl
dec di
pop cx
loop lpdiv
mov di,offset array
add di,startoffset
mov cx,length
dec cx
sub di,cx
lpzero: .if byte ptr [di]==30h
mov byte ptr [di],0
inc di
.else
jmp exit
.endif
loop lpzero
exit: pop di
endm
EMov macro destinH,destinL,sourceH,sourceL
mov ax,word ptr sourceL
mov word ptr destinL,ax
mov ax,word ptr sourceH
mov word ptr destinH,ax
endm
EAdd macro destinH,destinL,sourceH,sourceL ;扩展加法(DWord+DWord=DWord,不溢出),[QWord目标操作数destin,QWord源操作数source]
mov ax,destinL
mov dx,destinH
mov cx,sourceL
mov bx,sourceH
add ax,cx
adc dx,bx
mov destinL,ax
mov destinH,dx
endm
EMul macro hexh,hexl,IER,destinh,destinl ;自己编写的扩展乘法(DWord*Word=QWord),[高字十六进制数hexh,低字十六进制数hexl,乘数IER,输出缓冲区(Qword)buffer]
mov bx,IER
mov ax,hexl
mul bx
mov destinl,ax
push dx
mov ax,hexh
mul bx
pop cx
add ax,cx
mov destinh,ax
endm
Hex2Ascii macro hex ;把十六进制数(0-9,A-F)转为ASCII码,[十六进制数hex]
.if hex>=0ah
add hex,7h
.endif
add hex,30h
endm
Ascii2Hex macro ascii ;把ASCII码转为十六进制数(0-9,A-F),[ASCII码ascii]
.if ascii>=41h
sub ascii,7h
.endif
sub ascii,30h
endm
HexByte2Ascii macro hex,asciih,asciil ;把一字节十六进制数转为两个ASCII码,[字节十六进制数hex,高字节十六进制数的ASCII码asciih,低字节十六进制数的ASCII码asciil]
push ax
push cx
mov al,hex
mov cx,4
shr al,cl
Hex2Ascii al
mov asciih,al
mov al,hex
and al,0fh
Hex2Ascii al
mov asciil,al
pop cx
pop ax
endm
HexWord2Ascii macro hex,asciihh,asciihl,asciilh,asciill ;把一字十六进制数转为四个ASCII码,[字十六进制数hex,高字高字节十六进制数的ASCII码asciihh,高字低字节十六进制数的ASCII码asciihl,低字高字节十六进制数的ASCII码asciilh,低字低字节十六进制数的ASCII码asciill]
mov dx,hex
HexByte2Ascii dh,asciihh,asciihl
HexByte2Ascii dl,asciilh,asciill
endm
Rectangle macro left,top,right,bottom,attr ;用单线画矩形,[开始点(left,top),结束点(right,bottom),属性attr]
GotoXY left,top
ShowChar_DOS 0dah
xor cx,cx
mov cl,right
sub cl,left
MulShowChar 0c4h,cx
push cx
GotoXY right,top
ShowChar_DOS 0bfh
mov dh,top
inc dh
.while dh!=bottom
GotoXY left,dh
push dx
ShowChar_DOS 0b3h
pop dx
GotoXY right,dh
push dx
ShowChar_DOS 0b3h
pop dx
inc dh
.endw
GotoXY left,bottom
ShowChar_DOS 0c0h
pop cx
MulShowChar 0c4h,cx
GotoXY right,bottom
ShowChar_DOS 0d9h
endm
DRectangle macro left,top,right,bottom ;用双线画矩形,[开始点(left,top),结束点(right,bottom),属性attr]
GotoXY left,top
ShowChar_DOS 0c9h
xor cx,cx
mov cl,right
sub cl,left
MulShowChar 0cdh,cx
push cx
GotoXY right,top
ShowChar_DOS 0bbh
mov dh,top
inc dh
.while dh!=bottom
GotoXY left,dh
push dx
ShowChar_DOS 0bah
pop dx
GotoXY right,dh
push dx
ShowChar_DOS 0bah
pop dx
inc dh
.endw
GotoXY left,bottom
ShowChar_DOS 0c8h
pop cx
MulShowChar 0cdh,cx
GotoXY right,bottom
ShowChar_DOS 0bch
endm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -