再是用数据段的情况下,向显存发送…

来源:互联网 发布:知乎 长沙的知名企业 编辑:程序博客网 时间:2024/04/30 12:45
之前傻逼了,上一篇里面的注说的没有错
【注】之前我把书中光盘的内容直接拿来编译,发现编译不通过,我也不知道为什么,后来我就按书上的代码改,没有用堆栈,但是用了数据段。数据段的数据在初始化时,是要把段首地址存在ds的,然后用数据段的数据就用偏移就可以,只是不知道为什么,我在代码段引用数据段的内容时,要么说是无效的有效地址,要么显示的全'S',所以索性先不用数据段,直接把字符串存在代码段,先这样把显存这部分先搞懂再说,接下来再好好研究如何使用数据段

但是,要注意记得初始化数据段的描述符,还有ds
这里就直接贴上代码了,追加的地方用红色标注了
%include "pm.inc"

org 07c00h
jmp LABEL_BAGIN

;----------------------------------------------------------------------------------------
[SECTION .gdt]
LABEL_GDT: Descriptor 0,        0,           0
LABEL_DESC_CODE32: Descriptor 0,       CODE32_LEN,    DA_C + DA_32
LABEL_DESC_VIDEO: Descriptor 0B8000h,  0ffffh,       DA_DRW
LABEL_DESC_DATA: Descriptor 0,       DATA_LEN,     DA_DRW

GDT_LEN equ $ - LABEL_GDT
GDT_PTR dw GDT_LEN - 1
   dd 0
   
;----------------------------------------------------------------------------------------
SelectorCode32 equ LABEL_DESC_CODE32 - LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO - LABEL_GDT
SelectorData equ LABEL_DESC_DATA -LABEL_GDT

;----------------------------------------------------------------------------------------
[SECTION .data]
LABEL_DATA:
kstring: db "Hello, Lily!"
koffset equ kstring - $$
DATA_LEN equ $ - LABEL_DATA -1

;----------------------------------------------------------------------------------------
[SECTION .s16]
[BITS 16]
LABEL_BAGIN:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0100h
xor eax, eax
mov ax, cs
shl eax, 4
add eax, LABEL_CODE32
mov word [LABEL_DESC_CODE32 + 2], ax
shr eax, 16
mov byte [LABEL_DESC_CODE32 + 4], al
mov byte [LABEL_DESC_CODE32 + 7], ah
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_DATA
mov word [LABEL_DESC_DATA + 2],ax
shr eax, 16
mov byte [LABEL_DESC_DATA + 4],al
mov byte [LABEL_DESC_DATA + 7],ah
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_GDT
mov dword [GDT_PTR + 2], eax
lgdt [GDT_PTR]
cli
in al, 92h
or al, 00000010b
out 92h, al
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword SelectorCode32:0

;----------------------------------------------------------------------------------------
[SECTION .s32]
[BITS 32]
LABEL_CODE32:
mov ax, SelectorVideo
mov gs, ax
mov ax, SelectorData
mov ds, ax
mov edi, (80 * 1 + 1) * 2
mov ah, 0Ch
xor esi, esi
xor edi, edi
mov esi, koffset
cld
disp_loop:
lodsb
mov [gs:edi], ax
add edi, 2
sub al, "!"
jnz disp_loop
jmp $
CODE32_LEN equ $ - LABEL_CODE32 - 1
MyString: db "Hello, kaito!"
原创粉丝点击