[Ensamblaje] Realice la conversión de color y dibuje gráficos (código fuente .asm)

Entorno del proyecto
  • Entorno de compilación: cree un entorno de compilación nasm2.8 .
  • Archivo espejo: use winhex_18.2 para cepillar el código.
  • Máquina virtual: se utiliza Bochs-2.4.5 .
Software de proyectos
resultado de la operación

Inserte la descripción de la imagen aquí

Bloque de color personalizado
;编制自定义颜色
editcolor:
	;设置颜色号接口0x3c8,RGB分量接口0x3c9
	mov dx,0x3c8
	mov al,[si]
	out dx,al

	mov dx,0x3c9
	mov al,[si+1]
	out dx,al

	mov al,[si+2]
	out dx,al

	mov al,[si+3]
	out dx,al

	add si,4

	ret
Código fuente del programa (.asm)
org 0x7c00

;CS,DS,ES,SS默认的段基址为0000
;利用jmp指令跳过段数据的定义部分
jmp start

;其中0号默认为背景色
;[1,+]为前景色
;XXX,笔画数为8,8,12,取公倍数160,160,240
;si
color:	db 0,255,255,255 
		db 2,0,0,0
	  
;bx
startP: dw 0 
		dw 319
		dw 63680
		dw 0
;ax
endP:	dw 319
		dw 63999
		dw 63999
		dw 63680
;主函数入口地址
start:	
	;进入13320*200 256色的图形模式
	mov ah,00h
	mov al,13h
	int 10h

	mov si,color;赋值底色
	call editcolor
	mov si,color;赋值黑色
	call editcolor

	;0xb800为显存的段基址
	mov ax,0xa000
	mov es,ax

	;整体框线1-----
	mov bx,[ds:startP]
    mov ax,[ds:endP]
    call DrawLineOfH
	;整体框线2|
	mov bx,[ds:startP]
    mov ax,[ds:endP]
    call DrawLineOfV
	;整体框线3-----
	mov bx,[ds:startP]
    mov ax,[ds:endP]
    call DrawLineOfH
	;整体框线4|
	mov bx,[ds:startP]
    mov ax,[ds:endP]
    call DrawLineOfV
e:	jmp $

;编制自定义颜色
editcolor:
	;设置颜色号接口0x3c8,RGB分量接口0x3c9
	mov dx,0x3c8
	mov al,[si]
	out dx,al

	mov dx,0x3c9
	mov al,[si+1]
	out dx,al

	mov al,[si+2]
	out dx,al

	mov al,[si+3]
	out dx,al

	add si,4

	ret

;横线
DrawLineOfH:
	cmp bx,ax
	ja DrawLineOfHExit
	mov byte [es:bx], 2
	inc bx
	jmp DrawLineOfH
DrawLineOfHExit:
	mov cx,word[ds:startP+2]
	mov word[ds:startP],cx
	mov cx,word[ds:endP+2]
	mov word[ds:endP],cx
	ret
;竖线
DrawLineOfV:
	cmp bx,ax
	ja DrawLineOfVExit
	mov byte [es:bx], 2
	add bx,320
	jmp DrawLineOfV
DrawLineOfVExit:
	mov cx,word[ds:startP+2]
	mov word[ds:startP],cx
	mov cx,word[ds:endP+2]
	mov word[ds:endP],cx
	ret

Supongo que te gusta

Origin blog.csdn.net/Gyangxixi/article/details/113613006
Recomendado
Clasificación