汇编语言 实现图形颜色变换
发布网友
发布时间:2022-05-18 06:37
我来回答
共3个回答
热心网友
时间:2023-10-10 11:32
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,2eh;Key '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,9600H;80*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
热心网友
时间:2023-10-10 11:33
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,2eh;Key
'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,9600H;80*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
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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
热心网友
时间:2023-10-10 11:33
不要找答案了 刚刚验证过了 DIDIDU1515 代码超棒