關於SEGMENT 宣告變數的問題
各位前輩好,以下的程式為在 big_real_mode 讀取記憶體的值,例如: C:\memory.exe(程式檔名) 01000100(Address)則會顯示01000100位置的值,但是我另外在DSEG SEGMENT USE16'data'
宣告了Maddress Dword 0,但是程式執行時,會hand住,麻煩前輩給我一些指導,謝謝
.model small
.386p
DSEG SEGMENT USE16'data'
DESC STRUC
LimitL DW 0
BaseL DW 0
BaseM DB 0
Attributes DB 0
LimitH DB 0
BaseH DB 0
DESC ENDS
PDesc STRUC
Limit DW 0
Base DD 0
PDesc ENDS
GDT_def Label Fword
Null_Desc DESC < 0h, 0h, 00h, 00h, 000h, 0>
Data_Desc DESC < 0FFFFh, 0h, 00h, 92h, 0CFh, 0>
GDT_Addr PDesc <$-GDT_def-1, >
Maddress Dword 0
DSEG ENDS
ASSUME CS:CSEG,DS:DSEG
CSEG SEGMENT USE16'code'
push ds
push es
push fs
push gs
call big_real_mode
call Get_Commandtail
xor ebx,ebx
mov si,82h
mov al,es:
cmp al,'r'
je R
cmp al,'R'
je R
cmp al,'w'
je W
cmp al,'W'
je W
R:
mov si,84h
mov al,es:
cmp al,'b'
je RBT
cmp al,'B'
je RBT
cmp al,'w'
je RWR
cmp al,'W'
je RWR
cmp al,'d'
je RDR
cmp al,'D'
je RDR
W:
mov si,84h
mov al,es:
cmp al,'b'
je WBT
cmp al,'B'
je WBT
cmp al,'w'
je WWR
cmp al,'W'
je WWR
cmp al,'d'
je WDR
cmp al,'D'
je WDR
RBT:
call PSP
call crlf
mov esi,ebx
mov eax,fs:
out 80h,eax
mov ebx,eax
call _8bits
jmp Exit
RWR:
call PSP
call crlf
mov esi,ebx
mov eax,fs:
out 80h,eax
mov ebx,eax
call _16bits
jmp Exit
RDR:
call DPSP
call crlf
mov esi,ebx
mov eax,fs:
out 80h,eax
mov ebx,eax
call _32bits
jmp Exit
;------------------------------------------------------------------------------------------------
WBT:
jmp Exit
WWR:
jmp Exit
WDR:
call DPSP
mov Maddress,ebx
call crlf
call WDPSP
mov eax,ebx
mov esi,Maddress
mov fs:,eax
out 80h,eax
jmp Exit
;------------------------------------------------------------------------------------------------
Exit:
call real_mode
pop gs
pop fs
pop es
pop ds
.exit
;------------------------------------------------------------------------------------------------
big_real_mode proc near
in al, 92h
or al, 002
out 092h, al
out 0edh, al
cli
mov eax,DSEG
shl eax, 4
xor ebx, ebx
mov ebx, offset GDT_def
add eax, ebx
mov dword ptr GDT_Addr.Base, eax
lgdt fword ptr GDT_Addr
mov bx, 8
mov eax, cr0
or al, 1
mov cr0, eax
jmp PMod
PMod:
mov fs, bx
mov gs, bx
mov eax,cr0
and al, 0FEh
mov cr0, eax
jmp RMod
RMod:
xor ax, ax
mov fs, ax
mov gs, ax
sti
ret
big_real_mode ENDP
;------------------------------------------------------------------------------------------------
real_mode proc near
in al, 92h
and al, 02
out 92h, al
ret
real_mode ENDP
;------------------------------------------------------------------------------------------------
Get_Commandtail PROC near
mov ah,62h
int 21h
mov es,bx
ret
Get_Commandtail ENDP
;------------------------------------------------------------------------------------------------
PSP proc near
xor ebx,ebx
mov si,89h
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
ret
PSP endp
;================================================================================================
DPSP proc near
xor ebx,ebx
mov si,8ah
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
ret
DPSP endp
;================================================================================================
WDPSP proc near
xor eax,eax
xor ebx,ebx
mov si,93h
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
mov al,es:
call Change
mov cl,4
shl ebx,cl
add ebx,eax
ret
WDPSP endp
;================================================================================================
Change proc near
A:
movzxeax,al
mov edx,eax
cmp eax,'0'
jb A
cmp eax,'9'
ja B
sub eax,'0'
jmp short E
B:
and eax,0dfh
mov edx,eax
sub eax,37h
cmp eax,0ah
jb A
cmp eax,0fh
ja A
E:
push eax
call PRT
pop eax
CExit:
ret
Change endp
;------------------------------------------------------------------------------------------------
PRT proc near
mov ah,02h
int 21h
ret
PRT endp
;------------------------------------------------------------------------------------------------
crlf proc near
mov ah,02h
mov dl,0dh
int 21h
mov ah,02h
mov dl,0ah
int 21h
ret
crlf endp
;------------------------------------------------------------------------------------------------
_32bits proc near
pushad
mov cl,4
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
call print_4_bits
rol ebx,cl
popad
ret
_32bits endp
;------------------------------------------------------------------------------------------------
_16bits proc near
pusha
rol bx,cl
call print_4_bits
rol bx,cl
call print_4_bits
rol bx,cl
call print_4_bits
rol bx,cl
call print_4_bits
popa
ret
_16bits endp
;------------------------------------------------------------------------------------------------
_8bits proc near
pusha
rol bx,cl
call print_4_bits
rol bx,cl
call print_4_bits
popa
ret
_8bits endp
print_4_bits proc near
mov dx,bx
and dl,0fh
add dl,30h
cmp dl,3ah
jb print
add dl,7
print:
mov ah,2
int 21h
ret
print_4_bits endp
CSEG ends
END
页:
[1]