http://rapidshare.de/files/40841147/hl1.exe.html
Wednesday, November 05, 2008
file-open create
.model small
.data ;DATA SEGMENT
segm dw 00h
CNT DW 00H
fname db ' $'
buff db 100 dup(?)
msg1 db 10,13," FILE CREATED SUCCESSFULLY !!! $"
msg db 10,13," FILEIDS NOT CREATED !!! $"
msg2 db 10,13," TYPE THE TEXT AND PRESS @ TO STOP :$"
MSG4 DB 0AH,0DH,"$"
msg7 db 10,13," FILE CAN NOT BE READED !!! :$"
msg8 db 10,13," FILE CAN NOT BE CLOSED !!! :$"
msg6 db 10,13," FILE CAN NOT BE OPENED !!! :$"
msg9 db 10,13," FILE CAN NOT BE CREATED !!! :$"
msg10 db 10,13," READ FILE IS AS FOLLOWS !!! :$"
msg12 db 10,13," $"
FBUF DB ?
MENU db 10,13,"_________________________ MENU ____________________________"
db 10,13," "
db 10,13,"1] CREATE FILE "
db 10,13,"2] WRITE IN FILE "
db 10,13,"3] READ FILE "
db 10,13,"4] EXIT "
db 10,13," "
db 10,13,"PLEASE NETER YOUR CHOICE :$"
WRNG db 10,13,"WRONG CHOICE !!$"
CHOICE DB 00H
.code ;CODE SEGMENT
start:
mov ax,@data
mov ds,ax
;GET PSP SEGMENT ADDRESS
mov ah,62h
int 21h
mov es,bx
mov si,80h
mov cl,es:[si]
mov ch,00
dec cl
inc si
inc si
lea di,fname
back:mov bl,es:[si]
mov ds:[di],bl
inc di
inc si
dec cl
jnz back
mov cl,00h
mov ds:[di],cl ;STORE FILENAME IN "FNAME" BUFFER
MAIN: LEA DX,MENU
MOV AH,09H
INT 21H
MOV AH,01H ;ACCEPT CHOICE
INT 21H
MOV CHOICE,AL
CMP CHOICE,31H
JE CRE
CMP CHOICE,32H
JE WR
CMP CHOICE,33H
JE RD
CMP CHOICE,34H
JE END11
LEA DX,WRNG
MOV AH,09H
INT 21H
JMP MAIN
CRE: call create
JMP MAIN
WR:
call write
CALL CLOSE
JMP MAIN
RD: CALL OPEN
CALL READ
JMP MAIN
END11:JMP END1
;PROCEDURE TO CREATE FILE
CREATE PROC
mov ah,3ch ; FUNCTION TO CREATE FILE
lea dx,fname
mov cx,00h
int 21h
jc eRR4
mov segm,ax
mov ah,09h
lea dx,MSG12
int 21h
; SUCCESSFUL FILE CREATED
mov ah,09h
lea dx,MSG1
int 21h
RET
; ERROR IN FILE CREARION
ERR4: mov ah,09h
lea dx,MSG9
int 21h
ret
CREATE ENDP
; PROCEDURE TO WRITE IN TO FILE
WRITE PROC
mov ah,09h
lea dx,MSG2
int 21h
mov ah,09h
lea dx,MSG12
int 21h
LEA DI,BUFF
MOV BX,0000H
MOV AX,0000H
UP: MOV AH,01H
INT 21H
CMP AL,0DH
JNE UP2
MOV AH,02
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H
MOV DL,0AH
MOV [DI],DL
INC DI
INC BX
MOV DL,0DH
MOV [DI],DL
INC DI
INC BX
UP2: CMP AL,'@'
JE STOP
MOV [DI],AL
INC DI
INC BX
JMP UP
; WRITE IN TO FILE
STOP : MOV AL,0
INC BX
MOV [DI],AL
; FUNCTION TO WRITE FILE
MOV AH,40H
MOV CNT,BX
MOV BX,SEGM
LEA DX,BUFF
MOV CX,CNT
INT 21H
RET
WRITE ENDP
OPEN PROC
; FUNCTION TO OPEN FILE
MOV AH,3DH
LEA DX,FNAME
MOV AL,0
INT 21H ; 0 FOR NORMAL MODE
JC ERR3
MOV SEGM,AX
RET
ERR3 :LEA DX,MSG6
MOV AH,09H
INT 21H
RET
OPEN ENDP
READ PROC ; PROCEDURE TO READ FILE
LEA DX,MSG10
MOV AH,09H
INT 21H
mov ah,09h
lea dx,MSG12
int 21h
BACK1:
MOV AH,3FH
MOV BX,SEGM
MOV CX,1
LEA DX,FBUF
INT 21H
JC ERR1
MOV DL,FBUF
CMP DL,0
JE STP
CMP DL,1AH
JE STP
MOV AH,02H
INT 21H
JMP BACK1
ERR1:LEA DX,MSG7
MOV AH,09H
INT 21H
STP:RET
READ ENDP
CLOSE PROC
mov ah,3eh
mov bx,segm
int 21h
jc err2
ret
ERR2:LEA DX,MSG8
MOV AH,09H
INT 21H
ret
CLOSE ENDP
end1:mov ah,4ch
int 21h
END
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>