Showing posts with label Assembly language programs. Show all posts

ALP to simulate COPY command using PSP

, by Engineer's Vision


;ALP to simulate COPY command using PSP


.MODEL SMALL
DISP MACRO MSG
        LEA DX,MSG
        MOV AH,09H
        INT 21H
ENDM

.DATA
        MSG1 DB 10,13,"INVALID NAME !!!!!!!!!$"
        MSG2 DB 10,13,"FILE 1----NAME IS INVALID!!!!!!!$"
        MSG3 DB 10,13,"FILE 2----NAME IS INVALID!!!!!!!$"
        MSG4 DB 10,13,"CAN NOT OPEN.....$"
        MSG5 DB 10,13,"ERROR IN WRITING FILE.........$"
        MSG6 DB 10,13,"!!!!!!!!!SUCCESFULL!!!!!!!!!!!!!!$"
        MSG7 DB 10,13,"ERROR...$"
        msg8 db 10,13,"FILE EXIST ALREADY $"
        MSG9 DB 10,13,"2 nd FILE CREATED..$"

        ARR1 DB 25H DUP(0)
        ARR2 DB 25H DUP(0)
        ARR3 DB 100H DUP(0)

        COUNT DW ?
        FH1 DW ?
        FH2 DW ?

.CODE
        MOV AX,@DATA
        MOV DS,AX

        MOV AH,62H  ;DOS FUN GIVES SOURCE ADD OF PSP
        INT 21H


        MOV ES,BX   ;PSP OFFSET ADD TO ES

        MOV DI,0082H

        LEA SI,ARR1

        MOV BH,' '
        MOV CX,0000H

        CALL CHECKVALID

        CMP CH,08H
        JBE N1
        DISP MSG1
        JMP EXIT

N1:     CMP CL,03H
        JE N2
        DISP MSG2
        JMP EXIT

N2:     MOV CX,0000H
        LEA SI,ARR2
        INC DI
        MOV BH,0DH  ;ASCII VAL OF ENTER

        CALL CHECKVALID
        CMP CH,08H
        JBE N3
        DISP MSG1
        JMP EXIT

N3:     CMP CL,03H
        JE N4
        DISP MSG3
        JMP EXIT

;*********OPENING OF FILE 1**********

N4 :    MOV AH,3DH          ; FUNCTION FOR OPENING OF FILE

        MOV AL,02H          ; OPENES A FILE IN READ/WRITE MODE
        LEA DX,ARR1         ; LOAD EFFECTIVE ADDRESS
        INT 21H

        MOV FH1,AX      ; HANDLE OF FILE

        JNC N5             
               
        DISP MSG4
        JMP EXIT

;*********CALCULATING COUNT**********       
N5:     MOV AH,42H        ; FUNCTION FOR SETTING FILE POINTER
        MOV AL,02H        ; 02 SIGNIFIES END OF FILE
        MOV BX,FH1        ; HANDLE IN BX
        MOV CX,0000H      ; MSB OF OFFSET FROM START FO FILE
        MOV DX,0000H      ; LSB...........
        INT 21H        

        MOV COUNT,AX

        MOV AH,42H
        MOV AL,00H
        MOV BX,FH1
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

;**********READING FILE 1************
 L7 :   MOV AH,3FH              ; FUNCTION FOR READING FILE
        MOV BX,FH1              ; HANDLE IN BX
        MOV CX,COUNT            ; NO. OF BYTES TO BE READ IN CX
        LEA DX,ARR3         ; OFFSET OF ARRAY IN WHICH FILE CONTENTS ARE TO BE STORED
        INT 21H

      JC EXIT

;**********CHECK IF FILE EXIST********
        MOV AH,3DH          ; FUNCTION FOR OPENING OF FILE

        MOV AL,02H          ; OPENES A FILE IN READ/WRITE MODE
        LEA DX,ARR2         ; LOAD EFFECTIVE ADDRESS
        INT 21H

        MOV FH2,AX      ; HANDLE OF FILE

        JC NXT            
        DISP MSG8       
        JMP NN
;********SETTING FILE PTR**********
NN:     MOV AH,42H        ; FUNCTION FOR SETTING FILE POINTER
        MOV AL,02H        ; 02 SIGNIFIES END OF FILE
        MOV BX,FH2        ; HANDLE IN BX
        MOV CX,0000H      ; MSB OF OFFSET FROM START FO FILE
        MOV DX,0000H      ; LSB...........
        INT 21H        
        JMP N7

;**********CREATE NEW FILE NO 2*********************
NXT:

        MOV AH,3CH                ;CREATE FILE........
        MOV CX,0000H
        LEA DX,ARR2
         INT 21H
        MOV FH2,AX
        DISP MSG9
        JNC N7
        DISP MSG7
        JMP EXIT
;*********WRITE DATA****************

N7:    
        MOV AH,40H
        MOV BX,FH2
        MOV CX,COUNT
        LEA DX,ARR3
        INT 21H

        JNC N8
        DISP MSG7
        JMP EXIT
N8:     DISP MSG6

;**********EXIT**********************

EXIT:   MOV AH,4CH
        INT 21H

CHECKVALID PROC NEAR
        L1:     MOV AH,ES:[DI]
                CMP AH,2EH     ;.OPERATOR
                JNE C1
                JMP L3

        C1:     MOV [SI],AH
                INC SI
                INC DI
                INC CH
                JMP L1

       L3:      MOV [SI],AH
                INC SI
                INC DI

       C2:      MOV AH,ES:[DI]
                CMP AH,BH
                JNE L4

                JMP GO
       L4:      MOV [SI],AH
                INC SI
                INC DI
                INC CL
                JNZ C2
       GO:      RET
ENDP
END
read more

ALP to simulate TYPE command using PSP

, by Engineer's Vision


;ALP to simulate TYPE command using PSP


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

.model small
.stack 100
.data
        msg1 db 10,13,"File is open$"
        msg2 db 10,13,"Error in opening file$"
        msg3 db 10,13,"File can be read$"
        msg4 db 10,13,"Not able to read file$"
        arr1 db 20h dup(0)
        arr2 db 20h dup(0)
        handle dw ?
        d dw ?
.code
        mov ax,@data
        mov ds,ax
       
        mov ah,62h      ;dos fun gives source addr
        int 21h

        mov es,bx

        mov di,0082h    ;starting add of psp
        lea si,arr1
l1:     mov ah,es:[di]
        cmp ah,0dh
        jne r1
        jmp l3

r1:     mov [si],ah
        inc si
        inc di
        jmp l1
       
l3:     mov ah,3dh      ;opening file
        mov al,02h      ;dos command for read/write
        lea dx,arr1
        int 21h

        mov handle,ax
        jc l6
        disp msg1       ;open
        jmp r5

l6:     disp msg2       ; not open
        jmp l4

r5:     mov ah,42h
        mov al,02h      ;end of file
        mov bx,handle
        mov cx,0000h
        mov dx,0000h
        int 21h

        mov d,ax

        mov ah,42h
        mov al,00h      ;start of file
        mov bx,handle
        mov cx,0000h
        mov dx,0000h
        int 21h

l7:     mov ah,3fh
        mov bx,handle
        mov cx,d
        lea dx,arr2
        int 21h
        jc r2
        disp msg3       ;file can be read
        lea si,arr2
        jmp l8
r2:     disp msg4       ;can not read
        jmp l4

l8:
        mov dx,[si]
        mov ah,02h
        int 21h
        inc si
        dec cx
        jnz l8

l4:     mov ah,4ch
        int 21h
end


read more

ALP to MOUSE KEYBOARD INTERFACE

, by Engineer's Vision


ALP to MOUSE KEYBOARD INTERFACE

divi macro number  ;macro for number
mov ax,bx
mov dx,0000h
mov bx,number
div bx
mov bx,dx
mdov dx,ax
endm
dd
ddisp macro msg   ;macro for message
lea dx,msg
mov ah,09h
int 21h
endm

.model small  ;beginning of the program

.data         ;initializing the data segment

msg1 db 10,13,"mouse interfacing supporting :$"
msg2 db 10,13,"mouse interfacing Not supporting :$"
msg3 db 10,13,"Keyboard interfacing supporting :$"
msg4 db 10,13,"keyboard interfacing Not supporting :$"
number dw 0000h
x dw 0000h
y dw 0000h

.code         ;initialize the code segment

mov ax,@data
mov ds,ax
;print '.'
mov ah,02h
mov dh,10h    ;y-coordinate
mov dl,29h    ;x-coordinate
mov bh,00h    ;page no
int 10h

mov ah,0eh    ;to print the character at current cursor position
mov al,'.'    ;get character dot in al
mov bh,00h    ;page no
mov bl,02h    ;foreground colour
int 10h

;print '*'
mov ah,02h   
mov dh,00h    ;y-coordinate
mov dl,4fh    ;x-coordinate
mov bh,00h    ;page no
int 10h

mov ah,0eh    ;to print the character at current cursor position
mov al,'*'    ;get character star in al
mov bh,00h    ;page no
mov bl,02h   ;foreground colour
int 10h


mov ax,0000h            ;checking for mouse support is available
int 33h
cmp ax,0FFFFh
je l1
disp msg2
jmp exit

l1:disp msg1

mov ax,0001h      ;dos function for show pointer
int 33h

z : call mouse           ;(x,y coordinates)call mouse procedure


k:mov ah,0bh       ;dos function for keyboard interface
int 21h

cmp al,00h
je z

l3:mov ah,00h    ;dos function to read a character from keyboard
int 16h

cmp al,'h'
jne l4
mov ax,0002h      ;function to hide the mouse pointer
int 33h
jmp l3

l4:cmp al,'s'
jne l5
mov ax,0001h      ;function to show the mouse pointer
int 33h
jmp l3

l5:cmp al,'q'
je exit
exit:mov ah,4ch    ;termination
     int 21h

proc mouse near

mov ax,0003h    ;funtion to get the mouse position and button status
int 33h

mov x,cx        ;move cursor coordinates in x & y variables resp.
mov y,dx
;defining locus points for beep generation
cmp cx,10Ah  ;10Ah is hex eq of 266 bcd no
jc next
cmp dx,6Fh   ;6Fh is hex eq of 111 bcd no
jc next
cmp cx,1AFh  ;1AFh is hex eq of 431 bcd no
jnc next
cmp dx,0A2h  ;0A2h is hex eq of 162 bcd no
jnc next
call beeps   ;call beeps procedure

next:mov ah,02h    ;dos fun for int 10h to set the cursor position
mov bh,00h         ;page no
mov dl,10h         ;x- coordinate
mov dh,10h         ;y-coordinate
int 10h
mov bx,x
call hex_to_bcd    ;call hex to bcd procedure for printing x-coordinate
mov dl,':'
mov ah,02h         ;print ':'
int 21h
mov bx,y
call hex_to_bcd    ;call hex to bcd procedure for printing y-coordinate
ret
endp

proc hex_to_bcd near
divi 03e8h
call bcddisplay
divi 0064h
call bcddisplay
divi 000ah
call bcddisplay
divi 0001h
call bcddisplay
ret
endp

proc bcddisplay near
and dl,0fh
cmp dl,09h
jbe a
add dl,07h

a:add dl,30h
  mov ah,02h
  int 21h
ret
endp

proc beeps near
mov dl,07h     ;07h is the ascii eq of beep
mov ah,02h
int 21h
call delay     ;call delay procedure
ret
endp

proc delay near
mov cx,3000h
t:dec cx
jnz t
ret
endp

end
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