Showing posts with label ALP for DOS Protected Mode Interface(DPMI). Show all posts

Write ALP for DPMI

, by Prashant Gunjal

Write ALP for DPMI

.model small
.486P
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm

.data
msg1 db 10,13 ,"DPMI is present$"
msg2 db 10,13,"DPMI is not present$"
msg3 db 10,13,"memory allocated aready$"
msg4 db 10,13,"memory allocated manually$"
msg5  db 10,13,"GDT:$"
msg6 db 10,13,"LDT:$"
msg7 db 10,13,"MS:$"
msg8 db 10,13,"IDT:$"
msg9 db 10,13,"Task reg:$"

dpmi dw ? 
gdtr dq ?
ldtr dw ?
ms dw ?
idtr dq ?
taskreg dw ?


.code
mov ax,@data ;initializtion of the data seg
mov ds,ax

mov ax,1687h ;check dpmi
int 2fh

or ax,ax ;present if it is zero
jz l1

disp msg2
jmp exit1

l1:disp msg1
mov dpmi[0],di
mov dpmi[2],es

mov ah,4ah
int 21h

cmp si,0000h
jne l2
disp msg3
jmp l3

l2:mov bx,si
mov ah,48h
int 21h
jc exit1
disp msg4
mov es,ax

l3:
call dword ptr dpmi
sgdt gdtr
sldt ldtr
sidt idtr
smsw ms
str taskreg

disp msg5
mov bx,word ptr gdtr[4]
call print
mov bx,word ptr gdtr[2]
call print
mov bx,word ptr gdtr[0]
call print

disp msg6
mov bx,ldtr
call print

disp msg7
mov bx,ms
call print

disp msg8
mov bx,word ptr idtr[4]
call print
mov bx,word ptr idtr[2]
call print
mov bx,word ptr idtr[0]
call print

disp msg9
mov bx,taskreg
call print

exit1:
mov ah,4ch
int 21h


print proc near
mov cx,0404h
up:rol bx,cl
mov dx,bx
and dx,000fh
cmp dx,0009h
jbe next
add dx,0007h
next:
add dx,0030h
mov ah,02h
int 21h
dec ch
jnz up
ret
print endp
end

OUTPUT

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

Assembling file:   ass.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  474k


C:\tasm>tlink ass.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International


C:\tasm>ass

DPMI is present
memory allocated manually
GDT:BA33C19003FF
LDT:0048
MS:003B
IDT:BA33C59007FF
Task reg:0028
read more

ALP for DOS Protected Mode Interface(DPMI).

, by Engineer's Vision


ALP for DOS Protected Mode Interface(DPMI).



disp macro msg                  ;declaration of macro
lea dx,msg
mov ah,09h
int 21h
endm

.model small
.486p                           ;use to access pentium instruction set

.data
dpmi dw ?,?                     ;declaration of variables
gdtr dq ?
idtr dq ?
ldtr dw ?
msw dw ?
tr dw ?
msg1 db 10,13,"Processror supports protected mode $"
msg2 db 10,13,"Processor does not support protected mode $"
msg3 db 10,13,"Memory allocated by the system $"
msg4 db 10,13,"Error in allocating the memory $"
msg5 db 10,13,"Memory allocated manually $"
msg6 db 10,13,"$"
msg7 db 10,13,"Contents of GDTR is $"
msg8 db 10,13,"Contents of LDTR is $"
msg9 db 10,13,"Contents of IDTR is $"
msg10 db 10,13,"Contents of MSW is $"
msg11 db 10,13,"Contents of TR is $"


.code
mov ax,@data
mov ds,ax

mov ax,1687h                    ;use for checking presence of DPMI
int 2fh

cmp ax,0000h                   
je l1
disp msg2
jmp gend

l1 : disp msg1
     jmp l2

l2 : mov dpmi[0],di             ;es:di gives entry address of
     mov dpmi[2],es             ;protected mode
     mov bx,si
     jmp l3

l3 : mov ah,4ah                 ;use for checking memory availability
     int 21h                                  

     cmp si,0000h               
     je l5
     jmp l4

l4 : mov ah,48h                 ;use to allocate memory manually
     int 21h
     jc l6
     jmp l7

l5 : disp msg6
     disp msg3
     jmp l7

l6 : disp msg4
     jmp gend

l7 : disp msg6
     disp msg5
     mov es,ax                  ;starting address of memory location
     call dword ptr dpmi        ;calling of DPMI

     sgdt gdtr                  ;for storing contents of gdt in gdtr
     sldt ldtr                  ;for storing contents of ldt in ldtr
     sidt idtr                  ;for storing contents of idt in idtr
     smsw msw                   ;for storing contents in msw
     str tr                     ;for storing contents in tr

     mov bx,word ptr [gdtr+4]
     disp msg6
     disp msg7
     call display1
     mov bx,word ptr [gdtr+2]
     call display1
     mov bx,word ptr gdtr
     call display1

     mov bx,ldtr
     disp msg6
     disp msg8
     call display1

     mov bx,word ptr [idtr+4]
     disp msg6
     disp msg9
     call display1
     mov bx,word ptr [idtr+2]
     call display1
     mov bx,word ptr idtr
     call display1

     mov bx,msw
     disp msg6
     disp msg10
     call display1

     mov bx,tr
     disp msg6
     disp msg11
     call display1
     disp msg6
     jmp gend
    

proc display1 near              ;procedure for display

    
     mov cx,0404h
l8 : rol bx,0004h
     mov dx,bx
     and dx,000fh
     cmp dx,0009h
     jbe l9
     add dx,0007h

l9 : add dx,0030h
     mov ah,02h
     int 21h
     dec ch
     jnz l8
ret
endp

gend : mov ah,4ch               ;use for termination of program
       int 21h
       end


 ;OUTPUT

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\student>cd..

C:\Documents and Settings>cd..

C:\>cd tasm

C:\tasm>edit dpmi.asm

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
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\tasm>cls


C:\tasm>dpmi

Processror supports protected mode

Memory allocated manually

Contents of GDTR is 8003F00003FF

Contents of LDTR is 0048

Contents of IDTR is 8003F40007FF

Contents of MSW is 003B

Contents of TR is 0028

C:\tasm>
read more