计算机组成原理与汇编课程设计实验报告

写在开头:

汇编是真的原始人,我写个点到圆心距离公式都要写好几行,不像高级语言一个sqrt函数就解决了。就这一个实验写了1k+行代码,真是写的依托。

声明:本人汇编入门水平,佬们没必要浪费时间看这坨代码。

如果有任何违规的地方,请第一时间联系我,我会立即删除本文。

1、问题描述

图形变换程序设计

完成一个图形变换的程序,系统具有 4 种可选择的功能,按字母“Y”画一个用点组成的圆;按字母“S”画一个用不同颜色填充的三角形;按字母“Z”画一个用不同颜色填充的矩形;按“q”键退出。

需要解决的核心问题:

1.如何实现颜色的填充?

2.如何让颜色变得不同,即如何产生随机的颜色?

3.如何判断一个点是否在图形的内部,圆可以用点到圆心的距离小于等于半径,三角形该如何判断?矩形也很简单。

2、系统设计

1.上网搜索发现int 10h可以改变显示模式,进入特定的模式就可以用一些特定的中断来实现颜色的填充。

2.填充的颜色由bl寄存器的值来确定,所以问题就来到了如何产生随机数,调查发现计算机并不能产生真正意义上的随机数,只能产生伪随机数,最简单的伪随机数的产生方法:x_{n+1} = (a*x_{n}+c) \mod\ m

3.若点在三角形内部或三角形上,则该点与三角形三个顶点连线,分成的三个小三角形的面积之和等于原三角形的面积;若点在三角形外部,则分成的三个小三角形的面积之和大于原三角形的面积。每个三角形的面积可以用两条边的叉积(X)除以二来进行计算(在只知道三角形三个顶点的坐标的情况下),当然如果每个计算的面积都要除以二,那么每个计算的面积也可以不除以二(相当于在等式的两端同时乘二),这样可以减少设计的复杂度。

圆内的点的判定:

三角形的点的判定 :

3、源代码清单

函数结构:

check_out1:判断当前点是否在圆内,若是,则打印一个'.'出来。

check_out2:判断当前点是否在三角形内,若是,则打印一个带颜色的空格出来。

check_out3:画出任意四边形的另一个三角形。(四边形可以看成2个三角形的产物)

delay:进行一个空循环,让画出图形的过程更加容易可视化,不然速度太快了看不清过程。

main:根据输入的不同,进入不同的子函数部分。

4、运行结果测试与分析

圆的输出:

三角形的输出:

矩形的输出:

任意四边形的输出:

5.有待提升的地方

可以再设计一个爱心的形状(星形线)?

6.源代码

data SEGMENT;数据区
	fun1 db 'Y'
	fun2 db 'S'
	fun3 db 'Z'
	fun4 db 'q'
	fun5 db 'R'
	huanhang db 0dh,0ah,'$';换行
	youshouldknow db 'enter:Y to get a Circle,S to get a Triangle,Z to get a Rectangle,R to get a Quadrilateral,q to quit',0dh,0ah,'$';提示
	inputxCenter db 'enter two number to consist xCenter like 05 or 20:',0dh,0ah,'$';输入中心x的坐标
	inputyCenter db 'enter two number to consist yCenter like 05 or 20:',0dh,0ah,'$';输入中心y的坐标
	inputradius db 'enter two number to consist radius like 05 or 20:',0dh,0ah,'$';输入圆半径
	input_half_length db 'enter two number to consist half of lengths like 05 or 20:',0dh,0ah,'$';输入半长
	input_half_width db 'enter two number to consist half of widths like 05 or 20:',0dh,0ah,'$';输入半宽
	beforeenter1 db 'both xCenter,yCenter must greater than radius,xCenter+radius shoud be less than 79,yCenter+radius shoud be less than 24',0dh,0ah,'$'
	beforeenter2 db 'x must less than 79,y must less than 24',0dh,0ah,'$'
	beforeenter3 db 'xCenter must greater than dex,yCenter must greater than dey,xCenter+dex shoud be less than 79,yCenter+dey shoud be less than 24',0dh,0ah,'$'
	beforeenter4 db 'point 1 must be opposite to point 3,point 2 must be opposite to point 4,x must less than 79,y must less than 24',0dh,0ah,'$'
	err1_kind1 db 'xCenter must greater than radius!!!',0dh,0ah,'$'
	err1_kind2 db 'yCenter must greater than radius!!!',0dh,0ah,'$'
	err1_kind3 db 'xCenter+radius shoud be less than 79!!!',0dh,0ah,'$'
	err1_kind4 db 'yCenter+radius shoud be less than 24!!!',0dh,0ah,'$'
	err2_kind1 db 'x must less than 79!!!',0dh,0ah,'$'
	err2_kind2 db 'y must less than 24!!!',0dh,0ah,'$'
	err3_kind1 db 'xCenter must greater than dex!!!',0dh,0ah,'$'
	err3_kind2 db 'yCenter must greater than dey!!!',0dh,0ah,'$'
	err3_kind3 db 'xCenter+dex shoud be less than 79!!!',0dh,0ah,'$'
	err3_kind4 db 'yCenter+dey shoud be less than 24!!!',0dh,0ah,'$'
	inputx1 db 'enter two number to consist x1 like 05 or 20:',0dh,0ah,'$'
	inputy1 db 'enter two number to consist y1 like 05 or 20:',0dh,0ah,'$'
	inputx2 db 'enter two number to consist x2 like 05 or 20:',0dh,0ah,'$'
	inputy2 db 'enter two number to consist y2 like 05 or 20:',0dh,0ah,'$'
	inputx3 db 'enter two number to consist x3 like 05 or 20:',0dh,0ah,'$'
	inputy3 db 'enter two number to consist y3 like 05 or 20:',0dh,0ah,'$'
	inputx4 db 'enter two number to consist x4 like 05 or 20:',0dh,0ah,'$'
	inputy4 db 'enter two number to consist y4 like 05 or 20:',0dh,0ah,'$'
	xCenter db 79; 水平中心坐标
    yCenter db 10; 垂直中心坐标
    radius db 5; 圆半径
	up db 10;上边界
	down db 20;下边界
	left db 10;左边界
	right db 20;右边界
	dex db 5
	dey db 5
	sum dw ?
	dot db '.';点
	x1 db 5
	y1 db 5
	x2 db 5
	y2 db 15
	x3 db 15
	y3 db 20
	x4 db 15
	y4 db 10
	ssum dw ?
data ends
stack segment;堆栈区
	dw 1000h dup (?)
stack ends
code SEGMENT;代码区
    main proc far
    ASSUME cs:code,ds:data,ss:stack
    start:
	mov sp,9999H
	mov ax,data
	mov ds,ax
	mov bl,30h;种子b(1)=30h
replay:   
	mov ah,00h
	mov al,03h
	int 10h;恢复正常模式
	lea dx,youshouldknow
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	lea dx,huanhang
	mov ah,9h
	int 21H
	cmp al,fun1
	je function1
	cmp al,fun2
	je stop2
	cmp al,fun3
	je stop3
	cmp al,fun4
	je over
	cmp al,fun5
	je stop4
	jmp replay
over:
	mov ax,4c00h
	int 21H
	
stop2:
	jmp function2
stop3:
	jmp function3
stop4:
	jmp function4
function1:;输出一个圆形
	lea dx,beforeenter1
	mov ah,9h
	int 21H;输出总体提示

	lea dx,inputxCenter
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov xCenter,cl;输入中心x的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputyCenter
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov yCenter,cl;输入中心y的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputradius
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov radius,cl;输入r的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	mov cl,xCenter
	cmp cl,radius
	jl err1_k1
	add cl,radius
	cmp cl,79
	jg err1_k3
	mov cl,yCenter
	cmp cl,radius
	jl err1_k2
	add cl,radius
	cmp cl,24
	jg err1_k4
	jmp jisuan1  
err1_k1:
	lea dx,err1_kind1
	jmp err1
err1_k2:
	lea dx,err1_kind2
	jmp err1
err1_k3:
	lea dx,err1_kind3
	jmp err1
err1_k4:
	lea dx,err1_kind4
	jmp err1
err1:
	mov ah,9h
	int 21H;提示错误信息
	jmp function1
jisuan1:
	mov al,xCenter
	sub al,radius
	mov left,al;计算up
	mov al,xCenter
	add al,radius
	mov right,al;计算down
	mov al,yCenter
	sub al,radius
	mov up,al;计算left
	mov al,yCenter
	add al,radius
	mov down,al;计算right

	mov ah,00h
	mov al,06h
	int 10h; 设置屏幕模式

	mov dh,up
nextdh1:
	mov dl,left
nextdl1:
	call check_out1
	call delay
	inc dl
	cmp dl,right
	jle nextdl1
	inc dh
	cmp dh,down
	jle nextdh1
	mov ah,02h
	mov dx,0
	mov bx,0
	int 10h
	mov ah,01h
	int 21H
	jmp replay;
function2:;输出一个三角形
	lea dx,beforeenter2
	mov ah,9h
	int 21H;输出总体提示

	lea dx,inputx1
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x1,cl;输入x1的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputy1
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y1,cl;输入y1的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputx2
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x2,cl;输入x2的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputy2
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y2,cl;输入y2的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputx3
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x3,cl;输入x3的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputy3
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y3,cl;输入y3的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	cmp x1,79
	jg err2_k1
	cmp y1,24
	jg err2_k2
	cmp x2,79
	jg err2_k1
	cmp y2,24
	jg err2_k2
	cmp x3,79
	jg err2_k1
	cmp y3,24
	jg err2_k2
	jmp jisuan2
err2_k1:
	lea dx,err2_kind1
	jmp err2
err2_k2:
	lea dx,err2_kind2
	jmp err2	
err2:
	mov ah,9h
	int 21H;提示错误信息
	jmp function2
jisuan2:
	mov ax,cx

	mov ch,x1
	mov cl,x2
	cmp ch,cl
	jl less1
	mov left,cl
	jmp nextleft
less1:
	mov left,ch
nextleft:
	mov ch,left
	mov cl,x3
	cmp ch,cl
	jl leap1
	mov left,cl
leap1:;计算左边界left
	mov ch,y1
	mov cl,y2
	cmp ch,cl
	jl less2
	mov up,cl
	jmp nextup
less2:
	mov up,ch
nextup:
	mov ch,up
	mov cl,y3
	cmp ch,cl
	jl leap2
	mov up,cl
leap2:;计算上边界up
	mov ch,x1
	mov cl,x2
	cmp ch,cl
	jg greater1
	mov right,cl
	jmp nextright
greater1:
	mov right,ch
nextright:
	mov ch,right
	mov cl,x3
	cmp ch,cl
	jg leap3
	mov right,cl
leap3:;计算右边界right
	mov ch,y1
	mov cl,y2
	cmp ch,cl
	jg greater2
	mov down,cl
	jmp nextdown
greater2:
	mov down,ch
nextdown:
	mov ch,down
	mov cl,y3
	cmp ch,cl
	jg leap4
	mov down,cl
leap4:;计算下边界down
	mov cx,ax

	mov ah,00h
	mov al,03h
	int 10h;恢复正常模式
	mov ah,01h
	mov al,0Fh
	int 10h; 设置视频模式

	mov dh,up
nextdh2:
	mov dl,left
nextdl2:
	call check_out2
	call delay
	inc dl
	cmp dl,right
	jle nextdl2
	inc dh
	cmp dh,down
	jle nextdh2
	mov ah,01h
	int 21H
	jmp replay;
function3:;输出一个矩形
	lea dx,beforeenter3
	mov ah,9h
	int 21H;输出总体提示

	lea dx,inputxCenter
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov xCenter,cl;输入中心x的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputyCenter
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov yCenter,cl;输入中心y的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,input_half_length
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov dex,cl;输入dex的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,input_half_width
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov dey,cl;输入dey的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	mov cl,xCenter
	cmp cl,dex
	jl err3_k1
	add cl,dex
	cmp cl,79
	jg err3_k3
	mov cl,yCenter
	cmp cl,dey
	jl err3_k2
	add cl,dey
	cmp cl,24
	jg err3_k4
	jmp jisuan3
err3_k1:
	lea dx,err3_kind1
	jmp err3
err3_k2:
	lea dx,err3_kind2
	jmp err3
err3_k3:
	lea dx,err3_kind3
	jmp err3
err3_k4:
	lea dx,err3_kind4
	jmp err3
err3:
	mov ah,9h
	int 21H;提示错误信息
	jmp function3
jisuan3:
	mov al,xCenter
	sub al,dex
	mov left,al;计算up
	mov al,xCenter
	add al,dex
	mov right,al;计算down
	mov al,yCenter
	sub al,dey
	mov up,al;计算left
	mov al,yCenter
	add al,dey
	mov down,al;计算right

	mov ah,00h
	mov al,03h
	int 10h;恢复正常模式
	mov ah,01h
	mov al,0Fh
	int 10h; 设置视频模式

	mov dh,up
nextdh3:
	mov dl,left
nextdl3:
	mov ah,02h
	mov bh,0
	int 10h
	mov ah,09h
	mov al,20h
	mov bh,0
	mov cx,1
	int 10h
	call delay
	mov al,bl;随机数算法开始:bl(n+1)=(3*bl(n)+5)mod255
	mov bl,3
	mul bl
	add ax,5
	mov bl,255
	div bl
	mov bl,ah;随机数算法结束
	inc dl
	cmp dl,right
	jle nextdl3
	inc dh
	cmp dh,down
	jle nextdh3

	mov ah,01h
	int 21H;按任意键继续
	jmp replay;
function4:;输出一个四边形
	lea dx,beforeenter4
	mov ah,9h
	int 21H;输出总体提示

	lea dx,inputx1
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x1,cl;输入x1的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputy1
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y1,cl;输入y1的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputx2
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x2,cl;输入x2的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputy2
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y2,cl;输入y2的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputx3
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x3,cl;输入x3的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	lea dx,inputy3
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y3,cl;输入y3的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputx4
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov x4,cl;输入x4的值
	lea dx,huanhang
	mov ah,9h
	int 21H

	lea dx,inputy4
	mov ah,9h
	int 21H;输出提示信息
	mov ah,01h
	int 21H
	sub al,'0'
	mov cl,10
	mul cl
	mov cl,al;读入十位
	mov ah,01h
	int 21H
	sub al,'0'
	add cl,al
	mov y4,cl;输入y4的值
	lea dx,huanhang
	mov ah,9h
	int 21H
	
	cmp x1,79
	jg err4_k1
	cmp y1,24
	jg err4_k2
	cmp x2,79
	jg err4_k1
	cmp y2,24
	jg err4_k2
	cmp x3,79
	jg err4_k1
	cmp y3,24
	jg err4_k2
	cmp x4,79
	jg err4_k1
	cmp y4,24
	jg err4_k2
	jmp jisuan4
err4_k1:
	lea dx,err2_kind1
	jmp err4
err4_k2:
	lea dx,err2_kind2
	jmp err4	
err4:
	mov ah,9h
	int 21H;提示错误信息
	jmp function4
jisuan4:

	mov ax,cx

	mov ch,x1
	mov cl,x2
	cmp ch,cl
	jl less3
	mov left,cl
	jmp nextleft1
less3:
	mov left,ch
nextleft1:
	mov ch,left
	mov cl,x3
	cmp ch,cl
	jl leap5
	mov left,cl
leap5:;计算左边界left
	mov ch,y1
	mov cl,y2
	cmp ch,cl
	jl less4
	mov up,cl
	jmp nextup1
less4:
	mov up,ch
nextup1:
	mov ch,up
	mov cl,y3
	cmp ch,cl
	jl leap6
	mov up,cl
leap6:;计算上边界up
	mov ch,x1
	mov cl,x2
	cmp ch,cl
	jg greater3
	mov right,cl
	jmp nextright1
greater3:
	mov right,ch
nextright1:
	mov ch,right
	mov cl,x3
	cmp ch,cl
	jg leap7
	mov right,cl
leap7:;计算右边界right
	mov ch,y1
	mov cl,y2
	cmp ch,cl
	jg greater4
	mov down,cl
	jmp nextdown1
greater4:
	mov down,ch
nextdown1:
	mov ch,down
	mov cl,y3
	cmp ch,cl
	jg leap8
	mov down,cl
leap8:;计算下边界down
	mov cx,ax

	mov ah,00h
	mov al,03h
	int 10h;恢复正常模式
	mov ah,01h
	mov al,0Fh
	int 10h; 设置视频模式

	mov dh,up
nextdh4:
	mov dl,left
nextdl4:
	call check_out2
	call delay
	inc dl
	cmp dl,right
	jle nextdl4
	inc dh
	cmp dh,down
	jle nextdh4

	mov ax,cx

	mov ch,x1
	mov cl,x3
	cmp ch,cl
	jl less5
	mov left,cl
	jmp nextleft2
less5:
	mov left,ch
nextleft2:
	mov ch,left
	mov cl,x4
	cmp ch,cl
	jl leap9
	mov left,cl
leap9:;计算左边界left
	mov ch,y1
	mov cl,y3
	cmp ch,cl
	jl less6
	mov up,cl
	jmp nextup2
less6:
	mov up,ch
nextup2:
	mov ch,up
	mov cl,y4
	cmp ch,cl
	jl leap10
	mov up,cl
leap10:;计算上边界up
	mov ch,x1
	mov cl,x3
	cmp ch,cl
	jg greater5
	mov right,cl
	jmp nextright2
greater5:
	mov right,ch
nextright2:
	mov ch,right
	mov cl,x4
	cmp ch,cl
	jg leap11
	mov right,cl
leap11:;计算右边界right
	mov ch,y1
	mov cl,y3
	cmp ch,cl
	jg greater6
	mov down,cl
	jmp nextdown2
greater6:
	mov down,ch
nextdown2:
	mov ch,down
	mov cl,y4
	cmp ch,cl
	jg leap12
	mov down,cl
leap12:;计算下边界down
	mov cx,ax

	mov dh,up
nextdh5:
	mov dl,left
nextdl5:
	call check_out3
	call delay
	inc dl
	cmp dl,right
	jle nextdl5
	inc dh
	cmp dh,down
	jle nextdh5

	mov ah,01h
	int 21H
	jmp replay;
main endp
;检查光标的点是否在圆内((xCenter-x0)^2+(yCenter-y0)^2<=radius^2?),若在圆内,则输出一个点(.);若不在圆内,则无事发生
check_out1 proc
	push dx
	cmp dh,yCenter
	jle dx1
	mov al,dh
	sub al,yCenter
	mov dex,al
	jmp dex_over
dx1:
	mov al,yCenter
	sub al,dh
	mov dex,al;计算dx
dex_over:
	mul al
	mov sum,ax
	cmp dl,xCenter
	jle dy1
	mov al,dl
	sub al,xCenter
	mov dey,al
	jmp dey_over
dy1:
	mov al,xCenter
	sub al,dl
	mov dey,al
dey_over:
	mul al
	add sum,ax;计算dx平方+dy平方
	mov al,radius
	mul al
	cmp sum,ax
	jg pass1
	mov ah,02h
	mov bh,0
	int 10h
	mov ah,09h
	mov al,dot
	mov bh,0
	mov cx,1
	int 10h
pass1:
	pop dx
	ret
;检查光标的点是否在三角形内(2*S(0,1,2)+2*S(0,1,3)+2*S(0,2,3)==2*S(1,2,3)?),若在三角形内,再判断颜色是否为黑色,若是,则换到下一个颜色;否则颜色不变;若不在三角形内,则无事发生
check_out2 proc
	push dx

	mov al,dl
	mov cl,y2
	mul cl
	mov si,ax
	mov al,x2
	mov cl,y3
	mul cl
	add si,ax
	mov al,x3
	mov cl,dh
	mul cl
	add si,ax
	mov al,dl
	mov cl,y3
	mul cl
	sub si,ax
	mov al,x2
	mov cl,dh
	mul cl
	sub si,ax
	mov al,x3
	mov cl,y2
	mul cl
	sub si,ax
	cmp si,0
	jg store1
	neg si
store1:
	mov ssum,si;计算两倍的s1

	mov al,x1
	mov cl,dh
	mul cl
	mov si,ax
	mov al,dl
	mov cl,y3
	mul cl
	add si,ax
	mov al,x3
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,y3
	mul cl
	sub si,ax
	mov al,dl
	mov cl,y1
	mul cl
	sub si,ax
	mov al,x3
	mov cl,dh
	mul cl
	sub si,ax
	cmp si,0
	jg store2
	neg si
store2:
	add ssum,si;计算两倍的s2

	mov al,x1
	mov cl,y2
	mul cl
	mov si,ax
	mov al,x2
	mov cl,dh
	mul cl
	add si,ax
	mov al,dl
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,dh
	mul cl
	sub si,ax
	mov al,x2
	mov cl,y1
	mul cl
	sub si,ax
	mov al,dl
	mov cl,y2
	mul cl
	sub si,ax
	cmp si,0
	jg store3
	neg si
store3:
	add ssum,si;计算两倍的s3

	mov al,x1
	mov cl,y2
	mul cl
	mov si,ax
	mov al,x2
	mov cl,y3
	mul cl
	add si,ax
	mov al,x3
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,y3
	mul cl
	sub si,ax
	mov al,x2
	mov cl,y1
	mul cl
	sub si,ax
	mov al,x3
	mov cl,y2
	mul cl
	sub si,ax
	cmp si,0
	jg compare
	neg si

compare:
	cmp ssum,si
	jg pass2
	mov ah,02h
	mov bh,0
	int 10h

	cmp bl,16
	jg not_black
	add bl,16

not_black:
	mov ah,09h
	mov al,20h
	mov bh,0
	mov cx,1
	int 10h
	mov al,bl;随机数算法开始:bl(n+1)=(3*bl(n)+5)mod255
	mov bl,3
	mul bl
	add ax,5
	mov bl,255
	div bl
	mov bl,ah;随机数算法结束
pass2:
	pop dx
	ret
;画出四边形的另一个三角形,方式同check_out2
check_out3 proc
	push dx

	mov al,dl
	mov cl,y3
	mul cl
	mov si,ax
	mov al,x3
	mov cl,y4
	mul cl
	add si,ax
	mov al,x4
	mov cl,dh
	mul cl
	add si,ax
	mov al,dl
	mov cl,y4
	mul cl
	sub si,ax
	mov al,x3
	mov cl,dh
	mul cl
	sub si,ax
	mov al,x4
	mov cl,y3
	mul cl
	sub si,ax
	cmp si,0
	jg store4
	neg si
store4:
	mov ssum,si;计算两倍的s1

	mov al,x1
	mov cl,dh
	mul cl
	mov si,ax
	mov al,dl
	mov cl,y4
	mul cl
	add si,ax
	mov al,x4
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,y4
	mul cl
	sub si,ax
	mov al,dl
	mov cl,y1
	mul cl
	sub si,ax
	mov al,x4
	mov cl,dh
	mul cl
	sub si,ax
	cmp si,0
	jg store5
	neg si
store5:
	add ssum,si;计算两倍的s2

	mov al,x1
	mov cl,y3
	mul cl
	mov si,ax
	mov al,x3
	mov cl,dh
	mul cl
	add si,ax
	mov al,dl
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,dh
	mul cl
	sub si,ax
	mov al,x3
	mov cl,y1
	mul cl
	sub si,ax
	mov al,dl
	mov cl,y3
	mul cl
	sub si,ax
	cmp si,0
	jg store6
	neg si
store6:
	add ssum,si;计算两倍的s3

	mov al,x1
	mov cl,y3
	mul cl
	mov si,ax
	mov al,x3
	mov cl,y4
	mul cl
	add si,ax
	mov al,x4
	mov cl,y1
	mul cl
	add si,ax
	mov al,x1
	mov cl,y4
	mul cl
	sub si,ax
	mov al,x3
	mov cl,y1
	mul cl
	sub si,ax
	mov al,x4
	mov cl,y3
	mul cl
	sub si,ax
	cmp si,0
	jg compare1
	neg si

compare1:
	cmp ssum,si
	jg pass3
	mov ah,02h
	mov bh,0
	int 10h

	cmp bl,16
	jg not_black1
	add bl,16

not_black1:
	mov ah,09h
	mov al,20h
	mov bh,0
	mov cx,1
	int 10h
	mov al,bl;随机数算法开始:bl(n+1)=(3*bl(n)+5)mod255
	mov bl,3
	mul bl
	add ax,5
	mov bl,255
	div bl
	mov bl,ah;随机数算法结束
pass3:
	pop dx
	ret
;发生一个小延迟,用来将画图形的过程可视化。
delay proc 
	push cx
	push dx
	mov dx,600
D1: mov cx,40
D2: loop D2
	dec dx
	jnz D1
	pop dx
	pop cx
	ret

code ends
end start

 

专栏总结:

至此我的大二下生涯也算彻底结束了,向着悠闲的(X)忙碌(✓)大三生活出发咯

  • 15
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值