写一段汇编代码, 使用io端口 操作 vga
时间: 2024-03-21 19:44:05 浏览: 25
以下是一段使用 IO 端口操作 VGA 的汇编代码:
```
section .data
cursor_position equ 0x3D4
cursor_data equ 0x3D5
cursor_location dw 0x0000
section .text
global _start
_start:
; 设置光标位置为 0,0
mov ax, 0x0F00
mov word [cursor_location], ax
mov dx, cursor_position
mov ax, 0x0E
out dx, ax
inc dx
mov ax, byte [cursor_location]
out dx, al
inc dx
mov ax, byte [cursor_location+1]
out dx, al
; 在屏幕上输出一些文本
mov ah, 0x0E
mov al, 'H'
int 0x10
mov al, 'e'
int 0x10
mov al, 'l'
int 0x10
mov al, 'l'
int 0x10
mov al, 'o'
int 0x10
; 移动光标位置到 1,0
mov ax, 0x0100
add word [cursor_location], ax
mov dx, cursor_position
mov ax, 0x0E
out dx, ax
inc dx
mov ax, byte [cursor_location]
out dx, al
inc dx
mov ax, byte [cursor_location+1]
out dx, al
; 在屏幕上输出一些文本
mov ah, 0x0E
mov al, 'W'
int 0x10
mov al, 'o'
int 0x10
mov al, 'r'
int 0x10
mov al, 'l'
int 0x10
mov al, 'd'
int 0x10
; 程序结束
mov ah, 0x00
mov al, 0x4C
int 0x21
```
这段代码先使用 IO 端口 0x3D4 和 0x3D5 来设置 VGA 的光标位置,然后使用 INT 0x10 中断来在屏幕上输出文本。你可以将这段代码保存为文件,用汇编器进行编译、链接和运行测试。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)