Wednesday, November 05, 2008

dpmi

.model small
.486p

disp macro m
mov ah,09h
lea dx,m
int 21h
endm

.data
dpmi dw ?,?
idtr dq ?
gdtr dq ?
ldtr dw ?
msw dw ?
taskreg dw ?

nmem db 10,13, 'Sorry, not enough memory. $'
nopm db 10,13, 'Sorry, cannot switch to protected mode. $'
found db 10,13, 'Success. The DOS-Protected Mode Interface detected. $'
nfound db 10,13, 'Sorry, no DPMI mode detected. $'
msg db 10,13, 'IDTR contains $'
msg2 db 10,13, 'GDTR contains $'
msg3 db 10,13, 'LDTR contains $'
msg4 db 10,13, 'Machine Status Word (MSW) contains $'
msg5 db 10,13, 'Task register contains $'
hextab db '0123456789ABCDEF'

.code
.startup

mov bx,ds
mov ax,es
sub bx,ax
mov ax,sp
shr ax,4
add bx,ax
mov ah,4Ah
int 21h

mov ax,1687h
int 2fh
or ax,ax
jz exists
disp nfound
jmp exit

exists :
disp found
mov dpmi[0],di
mov dpmi[2],es

or si,si
jz gopm
mov bx,si
mov ah,48h
int 21h
jnc gopm
disp nmem
jmp exit

gopm : mov es,ax
mov ax,0
call dword ptr dpmi
jnc pmode
disp nopm
jmp exit

pmode :

sidt idtr
sgdt gdtr
sldt ldtr
smsw msw
str taskreg

disp msg
mov bx,word ptr [idtr + 2]
call conv
mov bx,word ptr [idtr + 4]
call conv
mov dl,':'
mov ah,2
int 21h
mov bx,word ptr [idtr + 6]
call conv

disp msg2
mov bx,word ptr [gdtr + 2]
call conv
mov bx,word ptr [gdtr + 4]
call conv
mov dl,':'
mov ah,2
int 21h
mov bx,word ptr gdtr
call conv

disp msg3
mov bx,word ptr[ldtr]
call conv

disp msg4
mov bx,word ptr[msw]
call conv

disp msg5
mov bx,word ptr[taskreg]
call conv

exit : mov ah,4Ch
int 21h

conv proc near

mov cx,4

digit : mov di,bx
and di,000Fh
mov dl,hextab[di]
mov ah,02h
int 21h
shr bx,4
loop digit
ret

conv endp
end




;*****************OUTPUT*******************

C:\TASM>tasm dpmi.asm
Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 Borland International

Assembling file: dpmi.asm
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 472k


C:\TASM>tlink dpmi.obj
Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\TASM>dpmi.exe

Success. The DOS-Protected Mode Interface detected.
IDTR contains 0958078F:0000
GDTR contains 0918078F:FF30
LDTR contains 8400
Machine Status Word (MSW) contains B300
Task register contains 8200
C:\TASM>

1 comments:

Anonymous said...

hi SHAILESH, why i always ge the error message from windows, warning no stack, could you give me advice how to study assembly for beginner, i use the old book for assembler dos v.2