帮我看看这段演示实模式和保护模式之间的转换的代码,我晕了
这段演示实模式和保护模式之间的转换的代码,我改来改去就是不能让它乖乖地运行,每次运行后只有一个结果:机器冷重起~~郁闷,不知道问题在哪里,请帮我看看我错在哪里啦
.386p
Descriptor struc
limitl dw 0
baselw dw 0
basehwlb db 0
attri db 0
limith db 0
basehwhb db 0
Descriptor ends
;***************************************************
JUMP16 MACRO Selector,Offset
db 0eah
dw Offset
dw Selector
ENDM
;-------------------------------
EnableA20 MACRO
IN AL,92H
OR AL,2
OUT 92H,AL
ENDM
;--------------------------------
DisableA20 MACRO
IN AL,92H
AND AL,0FDH
OUT 92H,AL
ENDM
;***************************************************
Data Segment use16
gdt0 LABEL BYTE
DUMMY Descriptor <>
CodeSel equ $-gdt0
CodeDes Descriptor <0ffffh,0,0,9ah,0,0>
DataSel equ $-gdt0
DataDes Descriptor <0ffffh,0,0,92h,0cf,0>
VideoSel equ $-gdt0
VideoDes Descriptor <0ffffh,8000h,0Bh,92h,0,0>
StkSel equ $-gdt0
StkDes Descriptor <0ffffh,0,0,96h,0,0>
;----------------------------------------------
GdtLen equ $-gdt0
GdtPtr dw GdtLen-1
dd 0
Buff db 256 dup (?)
Mesg db 'Now Is In Protect Mode. ',0
Data ends
;*************************************************
stk Segment STACK use16
db 1024 dup (0)
stk ends
;*************************************************
Code Segment use16
assume cs:Code,ds:Data,ss:stk
start:
xor ax,ax
mov ax,Data
mov ds,ax
mov bx,16
mul bx
add ax,offset gdt0 ;设置全局描述符表的基地址
adc dx,0
mov word ptr [GdtPtr+2],ax
mov word ptr [GdtPtr+4],dx
mov ax,Code ;设置代码段
mul bx
mov CodeDes.baselw,ax
mov CodeDes.basehwlb,dl
mov CodeDes.basehwhb,dh
mov ax,ss ;设置堆栈段
mul bx
mov StkDes.baselw,ax
mov StkDes.basehwlb,dl
mov StkDes.basehwhb,dh
mov ax,ds ;设置数据段
mul bx
add ax,offset Buff
adc dx,0
mov DataDes.baselw,ax
mov DataDes.basehwlb,dl
mov DataDes.basehwhb,dh
lgdt fword ptr GdtPtr
cli
EnableA20
;进入保护模式:
mov eax,cr0
or al,01h
nop
nop
nop
nop
nop ;for Debug
mov cr0,eax
JUMP16 CodeSel, <OFFSET ProtectCode> ; 刷新缓存
ProtectCode:
mov ax,StkSel
mov ss,ax
mov ax,DataSel
mov ds,ax
mov ax,VideoSel
mov es,ax
;直接写视频缓冲来显示提示消息:
mov esi,offset Mesg
mov edi,80*10
cld
mov ah,1eh
Load:
lodsb
cmp al,0
jz ReadyToReal
stosw
jmp Load
ReadyToReal: ;退回实模式:
mov eax,cr0
and al,0feh
mov cr0,eax
JUMP16 <SEG Real> , <OFFSET Real> ;刷新缓存
Real:
DisableA20
sti
mov ax,Data
mov ds,ax
mov es,ax
mov ax,stk
mov ss,ax
WAITKEY:
mov ah, 08h
int 21h
mov ax,4c00h
int 21h
Code ends
end start
[解决办法]
http://www.begin.org.cn/
上面有我改好的