組合語言(十)畫點+畫線+畫矩形+畫三角形
阿新 • • 發佈:2018-12-13
備戰本校組合語言競賽,先練練畫圖。
本文借鑑了學長大神的部落格:彙編---畫點+畫線
-
設定螢幕顯示模式
MOV AH,0
MOV AL,12H ;640*480*16
INT 10H
-
畫點巨集
;########畫細點巨集######## ;引數:頁面、Y座標、X座標、顏色,通過將AH放入0CH,通過10H中斷來描點 ;0黑色 1藍色 2綠色 3青色 4紅色 5紫色 6橙色 7白色 8灰色 POINT_THIN MACRO PAGE,ROW,COLUMN,COLOR PUSH AX PUSH BX PUSH CX PUSH DX MOV AH,0CH MOV AL,COLOR MOV BH,PAGE MOV DX,ROW MOV CX,COLUMN INT 10H POP DX POP CX POP BX POP AX ENDM
;########畫橫線巨集,引數:X座標、Y座標、長度、顏色
DRAWLINE1 MACRO COLUMN,ROW,FREE_LENGTH,COLOR
LOCAL LIN1
PUSH CX
PUSH SI
MOV CX,FREE_LENGTH
MOV SI,COLUMN
LIN1:
POINT_THIN 0,ROW,SI,COLOR
INC SI
LOOP LIN1
POP SI
POP CX
ENDM
-
畫任意兩點間線巨集
;畫任意兩點間線巨集。引數:起點X、起點Y、終點X、終點Y、顏色 LINE MACRO X1,Y1,X2,Y2,COLOR LOCAL EXIT LOCAL LINEZHENG,LINEFUN LOCAL LINEZHENGZHENG,LINEZHENGFUN LOCAL LINEFUNZHENG,LINEFUNFUN LOCAL LINE1,LINE2,LINE3 LOCAL LINE11,LINE12,LINE13 LOCAL LINE21,LINE22,LINE23 LOCAL LINE31,LINE32,LINE33 PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH DI MOV SI,0 MOV DI,0 MOV AX,X1 MOV BX,X2 MOV CX,Y1 MOV DX,Y2 CMP AX,BX JA LINEFUN LINEZHENG: CMP CX,DX JA LINEZHENGFUN LINEZHENGZHENG: MOV AH,0CH MOV AL,COLOR MOV BH,0 MOV CX,X1 MOV DX,Y1 LINE1:ADD SI,(Y2-Y1) CMP SI,(X2-X1) JBE LINE2 SUB SI,(X2-X1) INC DX LINE2:ADD DI,(X2-X1) CMP DI,(Y2-Y1) JBE LINE3 SUB DI,(Y2-Y1) INC CX LINE3:INT 10H CMP CX,X2 JB LINE1 LEA BX,EXIT JMP BX LINEZHENGFUN: MOV AH,0CH MOV AL,COLOR MOV BH,0 MOV CX,X1 MOV DX,Y1 LINE11:ADD SI,(Y1-Y2) CMP SI,(X2-X1) JBE LINE12 SUB SI,(X2-X1) DEC DX LINE12:ADD DI,(X2-X1) CMP DI,(Y1-Y2) JBE LINE13 SUB DI,(Y1-Y2) INC CX LINE13:INT 10H CMP CX,X2 JB LINE11 LEA BX,EXIT JMP BX LINEFUN: MOV CX,Y1 MOV DX,Y2 CMP CX,DX JA LINEFUNFUN LINEFUNZHENG: MOV AH,0CH MOV AL,COLOR MOV BH,0 MOV CX,X1 MOV DX,Y1 LINE21: ADD SI,(Y2-Y1) CMP SI,(X1-X2) JBE LINE22 SUB SI,(X1-X2) INC DX LINE22:ADD DI,(X1-X2) CMP DI,(Y2-Y1) JBE LINE23 SUB DI,(Y2-Y1) DEC CX LINE23:INT 10H CMP CX,X2 JA LINE21 JMP EXIT LINEFUNFUN: MOV CX,X1 MOV DX,Y1 MOV AH,0CH MOV AL,COLOR MOV BH,0 LINE31:ADD SI,(Y1-Y2) CMP SI,(X1-X2) JBE LINE32 SUB SI,(X1-X2) DEC DX LINE32:ADD DI,(X1-X2) CMP DI,(Y1-Y2) JBE LINE33 SUB DI,(Y1-Y2) DEC CX LINE33:INT 10H CMP CX,X2 JA LINE31 EXIT: POP DI POP SI POP DX POP CX POP BX POP AX ENDM