汇编语言实现图形变换程序设计!

汇编语言实现图形变换程序设计!,第1张

DATAS SEGMENT

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

编写一个程序,让红心在瞎樱察(0,0)到(24,24)上移动

CODES SEGMENT

ASSUME CS:CODES

START:

MOV AH,0建立彩色文本磨茄区80X25

MOV AL,3

INT 10H

STUD: 回到行首

MOV DX,0

PRINT: 打印斜线

MOV AH,2设置光标位置

MOV BH,0页号送BH

行颂慧号0送DH,列号0送DL

INT 10H

画心形图像,页号BH同上

MOV AX,903H 功能号9送AH,心ASCII码送AL

MOV BL,04H 字符属性闪烁的黑底红字

MOV CX,1重复次数

INT 10H

延时

MOV AX,3FFFH

REP2:

MOV CX,9FFFH

REP10MS:

LOOPREP10MS

DEC AX

CMP AX,0H

JNE REP2

清除上个字符

MOV AX,903H 功能号9送AH,心ASCII码送AL

MOV BL,0字符属性闪烁的黑底黑字

MOV CX,1重复次数

INT 10H

MOV CX,9FFFH

ADD DX,0101H行列号+1

CMP DX,1414H

JNE PRINT

JMP STUD

MOV AH,4CH

INT 21H

CODES ENDS

END START

说明:

1、本程序只识别三个按键:光标左移键、光标右移键和Esc键;

2、按光标左移键或光标右移键,执行相应的功能;按Esc键,结束程序。

本程掘段序通过编译,运行正确

Code Segment

Assume CS:Code,DS:Code

------------兆伍-----------------------------

功能:显示指定地址(Str_Addr)的字符串

入口:

Str_Addr=字符串地址(要求在数据段)

用法: Output Str_Addr

用法举例:Output PromptStr

Output MACRO Str_Addr

lea dx,Str_Addr

mov ah,9

int 21h

EndM

-----------------------------------------

功能:置光标位置

入口:Cursor_Row=行坐标Cursor_Col: 列坐标)

SetCursor Proc Near

PUSH CX

PUSH BX

PUSH AX

MOV DH,Cursor_Row

MOV DL,Cursor_Col

XOR BX,BX

MOV AH,2

INT 10H

POP AX

POP BX

POP CX

RET

Cursor_Row DB 21

Cursor_Col DB 36

SetCursor EndP

-----------------------------------------

KBEsc equ 11BH

KBLeft equ 4BH

KBRight equ 4DH

String db '<---->$'

Start: push cs

pop ds

push cs

pop es 使数据段、附加段与代码段同段

xor bh,bh

mov ah,8 读光标位置的字符和属性

int 10h

mov bh,ah 保存字符属性值

Disp_Str: call SetCursor 设置光标位置

Output String 显示一个字符串

Read_Key: xor ah,ah

int 16h 接收按键

cmp ax,KBEsc Esc?

jz Exit_Proc 结束程序,返回 *** 作系统

cmp ah,KBLeft 左箭头?

jnz $+10 不是,转去看是否右键

mov word ptr Inc_or_Dec,0efeh 是,当前列号减1

jmp Cursor_move

cmp ah,KBRight 右箭头?

jnz Read_Key 不是,接收下一个按键

mov word ptr Inc_or_Dec,06feh 是,当前列号加1

Cursor_move:mov bl,ah 保存按键方向

push bx

xor bh,bh

mov ah,3 取当前光标位置,窗口右下角坐标

int 10h

pop bx

inc dl 列号加1

mov ch,Cursor_Row 窗口左上角行号

mov cl,Cursor_Col 窗口左上角列号

.IF bl == KBLeft &&cl == 0 按左键,但已经到最左侧,不移动

jmp Read_Key

.ENDIF

.IF bl == KBRight &&dl == 79 按右键,但判猜誉已经到最右侧,不移动

jmp Read_Key

.ENDIF

mov ah,7 窗口显示内容下滚

mov al,1 下滚一行

int 10h

Inc_or_Dec: inc Cursor_Col 当前列号减1或加1

jmp Disp_Str

Exit_Proc: mov ah,4ch 结束程序

int 21h

Code ENDS

END Start 编译到此结束


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12413925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存