COLOR DW 02
BKCOLOR DW 15
X DW 280,
Y DW 240,
RADIUS DW 150
DATAS ENDS
STACKS SEGMENT
DW 100 DUP(0)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV AX,0A000H
MOV ES,AX
MOV AX,0012H
INT 10H 设置640*480*16图形迟缺模式
MOV AL,2
CALL SET_WRITE_MODE 将写模式设为写模式2
again:
MOV AX,BKCOLOR
CALL CLEAR 将背景清成白色
MOV AX,WORD PTR [X]
PUSH AX
MOV AX,WORD PTR [Y]
PUSH AX
MOV AX,WORD PTR [RADIUS]
PUSH AX
CALL CIRCLE
MOV AH,0
INT 16H
cmp al,0dh 回车退出
jz exit
cmp ah,2ehKey 'C or c'
jnz skip
inc color
skip:
jmp again
quit:
mov ah,4ch
int 21h
exit:
MOV AX,4C00H
INT 21H
******************************************
640*480*16模式下的画点函数
******************************************
PIXEL PROC
PUSH BP
PUSH BX
PUSH CX
PUSH DS
MOV BP,SP
MOV AX,80
MOV BX,WORD PTR[BP+12] BX<=Y
MUL BX (DX:AX)<=80*Y
MOV BX,AX
MOV AX,WORD PTR[BP+14] AX<--X
MOV CL,8 | |
DIV CL AL<=商(X/8),AH<=余数(X%8) SP->| |
MOV CL,AH CL<=AH | DS |<-BP
MOV AH,0 | CX |<-BP+2
ADD BX,AX BX(OFFSET)<=80*Y+X/8 | BX |<-BP+4
MOV AL,80H | BP |<-BP+6
SHR AL,CL AL(MASK)<=(80H>>CL) |返猜旦森回地址|<-BP+8
PUSH AX | COLOR |<-BP+10
MOV DX,3CEH | Y |<-BP+12
MOV AL,8 | X |<-BP+14
OUT DX,AL | |
MOV DX,3CFH PIXEL堆栈结构
POP AX
OUT DX,AL
MOV AL,ES:[BX]
MOV AX,WORD PTR[BP+10] AX<=COLOR
MOV BYTE PTR ES:[BX],AL
POP DS
POP CX
POP BX
POP BP
RET 6
PIXEL ENDP
********************************
清屏函数
********************************
CLEAR PROC NEAR
MOV BX,0
CLR1: MOV ES:[BX],AL
INC BX
CMP BX,9600H80*480
JNB CLR2
JMP CLR1
CLR2: RET
CLEAR ENDP
***************************************
Bresenham算法实现的画圆函数
***************************************
CIRCLE PROC NEAR
PUSH BP
MOV BP,SP
SUB SP,6
MOV WORD PTR[BP-2],0 X<=0 | |
MOV AX,WORD PTR[BP+4] | |
MOV WORD PTR[BP-4],AX Y<=R SP->穗亩 | |
MOV AX,0FFFEH | P |<-BP-6
IMUL WORD PTR[BP+4] AX<=RADIUS*(-2) | Y |<-BP-4
ADD AX,3 AX<=3-2*RADIUS | X |<-BP-2
MOV WORD PTR[BP-6],AX P=3-2*RADIUS | BP |<-BP
C0: MOV AX,WORD PTR[BP-2] AX<=X |返回地址|<-BP+2
CMP AX,WORD PTR[BP-4] IF X<Y,JMP C00 | RADIUS |<-BP+4
JL C00 | YC |<-BP+6
JMP C3 | XC |<-BP+8
C00: PUSH WORD PTR[BP+8] CIRCLE堆栈结构
PUSH WORD PTR[BP+6]
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-4]
CALL CIRCLE_POINT
CMP WORD PTR[BP-6],0
JGE C1
MOV AX,4
MUL WORD PTR[BP-2]
ADD AX,6
ADD AX,WORD PTR[BP-6]
MOV WORD PTR[BP-6],AX
JMP C2
C1: MOV AX,WORD PTR[BP-2]
SUB AX,WORD PTR[BP-4]
MOV BX,4
IMUL BX
ADD AX,10
ADD AX,WORD PTR[BP-6]
MOV WORD PTR[BP-6],AX
DEC WORD PTR[BP-4]
C2: INC WORD PTR[BP-2]
JMP C0
C3: MOV AX,WORD PTR[BP-2]
CMP AX,WORD PTR[BP-4]
JNE C4
PUSH WORD PTR[BP+8]
PUSH WORD PTR[BP+6]
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-4]
CALL CIRCLE_POINT
C4: MOV SP,BP
POP BP
RET 6
CIRCLE ENDP
CIRCLE_POINT PROC NEAR
PUSH BP
MOV BP,SP
SUB SP,16
MOV AX,WORD PTR[BP+10]
ADD AX,WORD PTR[BP+6]
MOV WORD PTR[BP-2],AX XC+X
MOV AX,WORD PTR[BP+10]
SUB AX,WORD PTR[BP+6]
MOV WORD PTR[BP-4],AX XC-X
MOV AX,WORD PTR[BP+10] | |
ADD AX,WORD PTR[BP+4] | |
MOV WORD PTR[BP-6],AX XC+Y | |
MOV AX,WORD PTR[BP+10] SP->| |
SUB AX,WORD PTR[BP+4] | YC-Y |<-BP-16
MOV WORD PTR[BP-8],AX XC-Y | YC+Y |<-BP-14
MOV AX,WORD PTR[BP+8] | YC-X |<-BP-12
ADD AX,WORD PTR[BP+6] | YC+X |<-BP-10
MOV WORD PTR[BP-10],AX YC+X | XC-Y |<-BP-8
MOV AX,WORD PTR[BP+8] | XC+Y |<-BP-6
SUB AX,WORD PTR[BP+6] | XC-X |<-BP-4
MOV WORD PTR[BP-12],AX YC-X | XC+X |<-BP-2
MOV AX,WORD PTR[BP+8] | BP |<-BP
ADD AX,WORD PTR[BP+4] |返回地址|<-BP+2
MOV WORD PTR[BP-14],AX YC+Y | Y |<-BP+4
MOV AX,WORD PTR[BP+8] | X |<-BP+6
SUB AX,WORD PTR[BP+4] | YC |<-BP+8
MOV WORD PTR[BP-16],AX YC-Y | XC |<-BP+10
PUSH WORD PTR[BP-2] | |
PUSH WORD PTR[BP-14] CIRCLE_POINT堆栈结构
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-4]
PUSH WORD PTR[BP-14]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-2]
PUSH WORD PTR[BP-16]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-4]
PUSH WORD PTR[BP-16]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-6]
PUSH WORD PTR[BP-10]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-8]
PUSH WORD PTR[BP-10]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-6]
PUSH WORD PTR[BP-12]
PUSH COLOR
CALL PIXEL
PUSH WORD PTR[BP-8]
PUSH WORD PTR[BP-12]
PUSH COLOR
CALL PIXEL
MOV SP,BP
POP BP
RET 8
CIRCLE_POINT ENDP
********************************
设置写模式的函数
********************************
SET_WRITE_MODE PROC NEAR
PUSH AX
MOV DX,3CEH
MOV AL,5
OUT DX,AL
MOV DX,3CFH
POP AX
OUT DX,AL
MOV DX,3CEH
MOV AL,8
OUT DX,AL
MOV DX,3CFH
MOV AL,0FFH
OUT DX,AL
RET
SET_WRITE_MODE ENDP
CODES ENDS
end start
ITSLEFT=30四边形左下角位置所拿态裤在列
ITSBUTTOM=5四边形左下角位置所在行
ITSHIGH=10高
ITSLEN=9底边长
ITSCHAR='8'字符
要定义四边形的左上角位置和形状、及字符,只需修改上述常量后重新编译运行即可
代码后附上调试结果截图
=====================================================================
FILE: SHOW88.ASM
To compile, use: ml -c SHOW88.ASM
To link, use: link16 SHOW88.OBJ
Author: HHHso 2013-05-03 8:58
SSEG SEGMENT
DB 100H DUP(0)
SSEG ENDS
DSEG SEGMENT
POS DB COL,ROW,CHAR
ITSLEFT=30四边形左下角位置所在列
ITSBUTTOM=5四边形左下角位置所在行
ITSHIGH=10高
ITSLEN=9底边长
ITSCHAR='8'字符
POS DB 0
REPT ITSHIGH
DB ITSLEFT,ITSBUTTOM,ITSCHAR
ITSLEFT=ITSLEFT+1
ITSBUTTOM=ITSBUTTOM+1
ENDM
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG,ES:DSEG,SS:SSEG
START:
MOV AX,DSEG
MOV DS,AX
MOV ES,AX
MOV AX,SSEG
MOV SS,AX
MOV SP,100H
LEA SI,POS
ADD SI,1
MOV CX,ITSHIGH
C1:
CALL SHOWPOSCHAR
ADD SI,3
LOOP C1
MOV AX,4C00H
INT 21H
SHOWPOSCHAR PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AH,02H
MOV BH,00H
MOV DX,[SI]
INT 10H
MOV AH,9
MOV AL,2[SI]
MOV BX,0007H
MOV CX,ITSLEN
INT 10H
POP DX
POP CX
POP BX
POP AX
RET
SHOWPOSCHAR ENDP
CSEG 消简ENDS
END START
==============================================
编译、链接、运行
ITSLEFT=15四边形左下角位置所在列
ITSBUTTOM=3四边形左下角位置所在行
ITSHIGH=8高闭誉
ITSLEN=19底边长
ITSCHAR='8'字符
修改为以上常量的编译、链接、运行结果
修改字符常量的运行结果
流程图(Flow Chart)历皮:使用图形表示算法的思路是一种极好的方法,因为千言万语不如一张图。流程图在汇编语言和早期的BASIC语言环境中得到应用。相关的还有一种PAD图,对PASCAL或C语言都极肢握差适用。以特定的图形符号加上说明,表示算法的图,称为流程图或框图。
流程图有时也称作输入-输出图。该图直观地描述一个工作过程的具体步骤。流程图对准确了解事情是如何进行的,以及决定应如何改进过程极有帮助。这一方法可以用于整个企业,以便直观地跟踪和图解企业的运作方式。
流程图中所用的图形包括:
圆角矩形:表示“开始”与“结束”,即起止框。
矩形:表示处理框,有一个进口和一个出皮谨口。
平行四边形:表示输入与输出,有一个进口和一个出口。
菱形:表示判断框,有一个进口和两个出口。
箭头:表示工作的流程方向。
这是基于原型概念的首款编译性面向对象编程语言。它还支持系统编程。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)