Showing posts with label HL. Show all posts

Write an 8051 ALP to interface stepper motor for following operations

, by Prashant Gunjal


;FULL STEP ANTICLOCKWISE

ORG 00H
L0:
MOV R0,#48H
MOV A,#099H
L1:
MOV P1,A
RL A
ACALL DELAY
DJNZ R0,L1
JMP L0
DELAY:
MOV R4,#0FFH
L2:
MOV R7,#0FFH
L3:
DJNZ R7,L3
DJNZ R4,L2
RET
END


;FULL STEP CLOCKWISE



ORG 0000H

L0:
MOV R0,#48H
MOV A,#0CCH
L1:
MOV P1,A
RR A
ACALL DELAY
DJNZ R0,L1
JMP L0
DELAY:
MOV R4,#0FFH
L2:
MOV R7,#0FFH
L3:
DJNZ R7,L3
DJNZ R4,L2
RET
END


;HALF STEP ANTICLOCKWISE



ORG 0000H

MOV A,#00H

L2:
MOV DPTR,#200H
MOV R0,08H
L1:
MOVC A,@A+DPTR
MOV P1,A
ACALL DELAY
INC DPTR
DJNZ R0,L1
SJMP L2
DELAY:
MOV R4,#0FFH
L3:
MOV R7,#0FFH
L4:
DJNZ R7,L4
DJNZ R4,L3
RET


;HALF STEP CLOCKWISE


ORG 0200H
DB 09H,01H,03H,02H,06H,04H,0CH,08H
END


ORG 0000H

MOV A,#00H

L2:
MOV DPTR,#200H
MOV R0,08H
L1:
MOVC A,@A+DPTR
MOV P1,A
ACALL DELAY
INC DPTR
DJNZ R0,L1
SJMP L2
DELAY:
MOV R4,#0FFH
L3:
MOV R7,#0FFH
L4:
DJNZ R7,L4
DJNZ R4,L3
RET

ORG 0200H
DB 08H, 0CH, 04H, 06H, 02H, 03H, 01H, 09H

END



read more

Write an 8051 ALP for serial port programming to transfer block of data using

, by Prashant Gunjal

a. Polling method

ORG 0000H

MSG: DB "WELCOME" ,0
MOV TMOD, #20H
MOV SCON, #50H
MOV TH1, #-3
SETB TR1
MOV DPTR, #MSG
L1:
CLR A
MOVC A,@A + DPTR
JZ L3
MOV SBUF,A
L2:
JNB TI,L2
INC DPTR
CLR TI
SJMP L1
L3:
END

b. ISP method


ORG 0000H
LJMP MAIN

ORG 0023H
CLR TI ;Transmitter Is Not Ready For Transmission.
INC DPTR ;Send Next Character.
CLR A
MOVC A,@A+DPTR ;Moves The String To Accumulator.
JZ L1
MOV SBUF,A
L1:
RETI

ORG 0030H
MSG: DB "WELCOME",0
MAIN:
MOV SCON, #50H ;Enable Mode 1 & Xmission Of SerialConrol Xmitter.
MOV TMOD, #20H ;Set Mode 2.
MOV TH1, #-3 ;Baud Rate Is 9600.
MOV IE,#90H
MOV DPTR, #MSG
SETB TR1 ;Timer 1 Run Control Bit.
CLR A ;Clear Accumulator.
MOVC A,@A + DPTR
JZ L2 ;String Is Over.
MOV SBUF,A ;Bit Is Set When Transmitter Is Ready ForTransmitter.
L3:
SJMP L3
L2:
END


read more

Write an 8051 ALP for rate generation using Timer0/Timer1 by using

, by Prashant Gunjal

a. Polling method


ORG 0000H

MOV P1,#00H
MOV TMOD,#10H
L1:
MOV TH1,#0FEH
MOV TL1,#034H
CPL P1.3
SETB TR1

HERE: JNB TF1,HERE
CLR TF1
CLR TR1
SJMP L1
END

b. ISR method

ORG 0000H

SJMP MAIN
ORG 000BH
CPL P1.3
RET

MAIN:  
CLR TF0
MOV IE,#82H
MOV P1,#00H
MOV TMOD,#01H
MOV TH0,#000H
MOV TL0,#000H
SETB TR0
WAIT: SJMP WAIT
END
read more

Write a C program for PC to PC communication.

, by Prashant Gunjal

Full duplex character transfer (chat application)

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<string.h>
union REGS in,out;
void init();
void transmit(char str);
void recive();
void main()
{
int ch,i,n=0;
char string[10],c1;
clrscr();
init();
do
{
printf("\nMENU");
printf("\n1.Transmit");
printf("\n2.Recive");
printf("\nEnter your choice=");
scanf("%d",&ch);
switch(ch)
{
case 1:
      printf("\nEnter data to transmit=");
      scanf("%s",&string);
      n=strlen(string);
      for(i=0;i<n;i++)
      {
transmit(string[i]);
      }
      transmit('\0');
      break;
case 2:
printf("\nRecived data is =");

recive();
break;
}
     printf("\nDo you want to continue(y/n)=");
     flushall();
     scanf("%c",&c1);
}while(c1=='y');
getch();
}
void init()
{
in.h.ah=0x0;
in.h.al=0xe3;
in.h.dh=0x0;
in.h.dl=0x0;
int86(0x14,&in,&out);
}
void transmit(char str)
{
in.h.ah=0x1;
in.h.al=str;
in.h.dh=0x0;
in.h.dl=0x0;
int86(0x14,&in,&out);

 if(out.h.ah && 0x01==1)
printf("\nData trasnmitted successfully");
 else
printf("\nError in data transmission");
}
void recive()
{
char c;
in.h.ah=0x2;
in.h.dh=0x0;
in.h.dl=0x0;
int86(0x14,&in,&out);
c=out.h.al;
if(c!='\0')
{
printf("%c",c);
      recive();
}
}

COMPUTER 1
****************OUTPUT*********************

MENU
1.Transmit
2.Recive
Enter your choice=1

Enter data to transmit=mmcoe

Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Do you want to continue(y/n)=y

MENU
1.Transmit
2.Recive
Enter your choice=2

Recived data is =prasad
Do you want to continue(y/n)=n

COMPUTR 2

****************OUTPUT*********************

MENU
1.Transmit
2.Recive
Enter your choice=2

Recived data is=mmcoe
Do you want to continue(y/n)=y

MENU
1.Transmit
2.Recive
Enter your choice=1

Enter data to transmit=prasad

Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Data trasnmitted successfully
Do you want to continue(y/n)=



read more

Write a C program for PC to PC communication.

, by Prashant Gunjal

FILE TRANSFER 

Transmitter : 

#include<stdio.h>
#include<conio.h>
#include<bios.h>
#include<string.h>
#include<stdlib.h>
#include<process.h>
#define setting (0x80|0x02|0x00|0x00)
#define com1 0
void main(int argc,char *argv[])
{
char str[15],ch='\0';
int i=0;
FILE *fp;
clrscr();
strcpy(str,argv[1]);
i=strlen(str);
str[i]='\0';
if(argc!=2)
{
printf("error");
getch();
exit(1);
}
i=0;
bioscom(0,setting,com1);
while(str[i]!='\0')
{
bioscom(1,str[i],com1);

i++;
}
bioscom(1,'\0',com1);
fp=fopen(argv[1],"r");
while(!feof(fp))
{
    ch=fgetc(fp);
    bioscom(1,ch,com1);
printf("%c",ch);
}


fclose(fp);
bioscom(1,'\0',com1);
getch();
}

Receiver : 

//receiver
#include<stdio.h>
#include<conio.h>
#include<bios.h>
#include<dos.h>
#include<process.h>
#include<string.h>
#include<stdlib.h>
#define setting (0x80 | 0x02 | 0x00 | 0x00)
#define com1 0
void main()
{
int i=0;
char ch='\0',fr[20];
FILE *fp;
clrscr();
bioscom(0,setting,com1);
flushall();
do
{
ch=bioscom(2,0,0);            ; for receive no data direct receive
if(ch=='\0')
break;
if(ch!=0x20)
{
printf("%c",ch);
fr[i]=ch;
i++;
}
}while(1);
fr[i]='\0';
fp=fopen(fr,"w");
do
{
ch=bioscom(2,0,0);
if(ch=='\0')
break;
printf("%c",ch);
fputc(ch,fp);
}while(1);
getch();
}


**********************OUTPUT***********************
Trasnmitter :

  Hardware lab Experiment

Receiver :

  Hardware lab Experiment
  

read more

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

Write ALP for Mouse interface

, by Prashant Gunjal

Write ALP for Mouse interface

H2B MACRO NO
        MOV AX,BX
        MOV BX,NO
        MOV DX,0000H
        DIV BX
        MOV BX,DX
        MOV DX,AX
ENDM
.MODEL SMALL
.DATA
        X DW ?
        Y DW ?
        Z DW ?
.CODE
        MOV AX,@DATA
        MOV DS,AX

;****SET CURSOR AT TOPMOST RIGHT CORNER*****
        MOV AH,02H
        MOV BH,00H
        MOV DL,4DH
        MOV DH,00H
        INT 10H

;****DISPLAY CHARACTER * AT THAT LOCN*******
        MOV AH,0EH
        MOV AL,'*'
        MOV BH,00H
        MOV BL,02H
        INT 10H

;****SET CURSOR AT CENTER OF DISPLAY*****
        MOV AH,02H
        MOV BH,00H
        MOV DL,27H
        MOV DH,0DH
        INT 10H

;****DISPLAY CHARACTER . AT THAT LOCN*******
        MOV AH,0EH
        MOV AL,'.'
        MOV BH,00H
        MOV BL,02H
        INT 10H

;*******INITIALIZE MOUSE*********
        MOV AX,0000H
        INT 33H

L1:     CALL STATUS

        ;***CHECK SUPPORT OF KEYOARD***
L2:     MOV AH,0BH
        INT 21H
        ;***SUPPORT AVAILABLE IF AL=FF**

        CMP AL,00H
        JE L1
        ;**IT COMES HERE FOR VALID VALUE ie AL!=00H***

        ;***READ CHARACTER FROM KEYBOARD***
        MOV AH,00H
        INT 16H

        CMP AL,'S'
        JE SHOW
        CMP AL,'H'
        JE HIDE
        CMP AL,'Q'
        JE EXIT

;******SHOW MOUSE PTR******
SHOW:   MOV AX,0001H
        INT 33H
        JMP L2
;******HIDE MOUSE PRT******
HIDE:   MOV AX,0002H
        INT 33H
        JMP L2
;*****TERMINATE PROGRAM******
EXIT:   MOV AH,4CH
        INT 21H

;****STATUS PROCEDURE******

STATUS PROC NEAR
;*****TAKE STATUS OF MOUSE PTR*****
        MOV AX,0003H
        INT 33H

        MOV X,CX
        MOV Y,DX
        MOV Z,BX

;****SET CURSOR AT LEFT SIDE OF . *****
        MOV AH,02H
        MOV BH,00H
        MOV DL,10H
        MOV DH,0DH
        INT 10H

        MOV BX,X
        H2B 03E8H
        CALL PRINT
        H2B 0064H
        CALL PRINT
        H2B 000AH
        CALL PRINT
        H2B 0001H
        CALL PRINT

;****DISPLAY CHARACTER : AT THAT LOCN*******
        MOV AH,0EH
        MOV AL,':'
        MOV BH,00H
        MOV BL,02H
        INT 10H
       
        MOV BX,Y
        H2B 03E8H
        CALL PRINT
        H2B 0064H
        CALL PRINT
        H2B 000AH
        CALL PRINT
        H2B 0001H
        CALL PRINT


        CALL BEEP
        CALL QUIT
RET
ENDP

PRINT PROC NEAR
        AND DL,0FH
        CMP DL,09H
        JBE N1
        ADD DL,07H
N1:     ADD DL,30H
        MOV AH,02H
        INT 21H
RET
ENDP

QUIT PROC NEAR
        CMP X,026AH
        JNE R
        CMP Y,0000H
        JNE R
        CMP Z,0001H
        JNE R1
        JMP EXIT
R:      RET
ENDP
BEEP PROC NEAR
        CMP X,0130H
        JB R1
        CMP X,0149H
        JA R1
        CMP Y,0061H
        JB R1
        CMP Y,0076H
        JA R1
        CMP Z,0001H
        JNE R1
        ;**BEEP**
        MOV DH,07H
        MOV AH,02H
        INT 21H
R1:     RET
ENDP
        
END

read more

Write an ALP / in line code for displaying file content using root directory and FAT for floppy disk.

, by Prashant Gunjal


Write an ALP / in line code for displaying file content using root directory and FAT for floppy disk.

#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<DOS.h>

typedef struct        // define a structure similar to a FAT entry
 {
  char file[8];      // file name
  char ext[3];       // file extension
  char res[15];      // rserved bits
  int fclust;        // starting cluster
  char fsize[4];     // size of file
 }ent;              // name of structure

void main()
 {
  int i,j,flag=1;
  ent a[224];            // total 224 entries array of structure
  char arr[512];         // array to store file contents

  char fn[20],ex[3];       // for acceptinf file name and extension
  int log,phy;
  clrscr();               // accept file name and extension from user

  printf("\n Enter the file name whose contents are to be read : ");
  gets(fn);
  printf("\n Enter the extension of above file : ");
  gets(ex);
// code to read all 224 entries from root directory
  asm{
    mov al,1          // drive number
    mov cx,14         // number of clusters to read
    mov dx,19         // starting cluster number
    lea bx,a           // array to store entries
    int 25h
   }

  for(i=0;i<224;i++)
   {
    for(j=0;j<8;j++)
     {
      if(a[i].file[j]==' ')
       {                        // enter null character to form a string
a[i].file[j]='\0';
       }
     }
     if(strcmpi(a[i].file,fn)==0)      // check if equal
      {
       printf("\n File name found !!");
       a[i].ext[3]='\0';
       if(strcmpi(a[i].ext,ex)==0)       // check for extension
{
printf("\n\n Extension Found !!");
flag=0;
break;              // if found then break loop i
}
       else
{
printf("\n Extension not found !!");
getch();
exit();         // else exit
}
      }
   }

  if(flag==1)
   {
    printf("\n File not found !!");
    getch();             // if unsuccessful exit
    exit();
   }
     // get logical cluster (starting cluster)
  log=a[i].fclust;
  printf("\n\n Logical cluster ( starting ) number : %d",log);
  phy=log+31;            // calculate the actual cluster (physical)

  if(phy<4095)
   {
    asm{                 // code for reading contents of cluster
      mov al,1
      mov cx,1
      mov dx,phy
      lea bx,arr
      int 25h              // print the contents of file
     }
    printf("\n\n File Contents : ");
    printf("%s",arr);
   }

  getch();
 }

/* OUTPUT

 Enter the file name whose contents are to be read : abc

 Enter the extension of above file : txt

 File name found !!

 Extension Found !!

 Logical cluster ( starting ) number : 2

 File Contents : hello...welcome to mmcoe */
read more

Write an installable DOS device driver for printers.

, by Prashant Gunjal


; TITLE : WRITE AN INSTALLABLE DOS DEVICE DRIVER FOR PRINTER



.model small
.code
org 00h

device_header:
link dd -1                    ;end of device driver
attr dw 08000h            ;char device driver printer
strat dw strgy              ;define strategy(data structure)
intr dw intpt ;interrupt routine entry point
logicalname db 'PRINTF  '     ;logical device name
   
  ;end of device header
  ;request header

req_header_off dw ?
req_header_seg dw ?

msg db 10,13, 'PRINTER DRIVER INSTALLED$'

strgy proc far                           ; procedure for strategy routine
mov cs:req_header_off,bx            ; get address from es:bx
mov cs:req_header_seg,es
retf                                           ;used to return from system function
endp

;*******************************************************

intpt proc  far          ; procedure for interrupt routine

pushf
push ax              ; push all the contents on to the stack
push bx
push cx
push dx
push ds
push es
push ss
push si
push di
push sp
push bp

mov bx,cs:req_header_off      ; restore the address of systems device drivers
mov es,cs:req_header_seg

mov al,es:[bx+2]             ; get command word in al
cmp al,00h                    ; if 00 then need to initialize the printer
jne next                      ; else already installed
call init                      ; call initialization procedure

next:   cmp al,08h          ; if equal printer ready to write
        jne next1
        call write           ; call write procedure

next1:  mov ax,0100h
           mov es:[bx+3],ax
        pop bp
        pop sp
        pop di               ; pop all the contents
        pop si               ; in proper order
        pop ss
        pop es
        pop ds
        pop dx
        pop cx
        pop bx
        pop ax
        popf
        retf             ;  return from system function

intpt endp

;*******************************************************

write proc near           ; procedure for printing the contents

mov cx,es:[bx+18]
mov si,es:[bx+14]
mov ds,es:[bx+16]

again:  mov ah,00h         ; function for writing character to printer
        mov al,ds:[si]       ; character to be printed
        mov dx,00h           ; printer number (LPT1=0, LPT2=1....)
        int 17h
        inc si                  ; points to next character
        loop again           ; loop untill value in cx register
        ret
write endp                   ; end of write procedure

;*******************************************************

init proc near            ; procedure for initialization of printer

lea dx,cs:msg            ; print message
mov ah,09h
int 21h

mov ah,01h            ; function for printer port initialization
mov dx,00h            ; printer name (LPT1=0)
int 17h

lea ax,init
mov es:[bx+14],ax

push cs
pop ax
mov es:[bx+16],ax
ret
init endp
end

; output

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

;C:\Documents and Settings\mmcoe>cd\

;C:\>cd tasm

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

;Assembling file:   printer.asm
;Error messages:    None
;Warning messages:  None
;Passes:            1
;Remaining memory:  476k


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

;C:\tasm>exe2bin printer.exe printer.com

;C:\tasm>

read more

Write an ALP / in line code for displaying boot sector of floppy and boot record of hard disk.

, by Prashant Gunjal


Write an ALP / in line code for displaying boot sector of floppy and boot record of hard disk.

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>

void main()
{
char boot[512],* ptr;
int i;
clrscr();

asm {
mov al,0;
mov cx,1;
mov dx,0;
lea bx,boot;
int 0x0025;
}
printf("\nOME no = ");
ptr=boot+0x0003;
for(i=0;i<8;i++)
{
printf(" %c",*ptr);
ptr++;
}
printf("\n*****************************");

printf("\nByte per sector:");
ptr=boot+0x000B;
printf("%d",*(int *)ptr);

printf("\n***************************");
printf("\nSector per cluster:");
ptr=boot+0x000D;
printf("%d",*ptr);

printf("\n***************************");
printf("\nNo of FAT directory entry:");
ptr=boot+0x0010;
printf("%d",*ptr);

printf("\n***************************");
printf("\nNo of Root directory entries:");
ptr=boot+0x0011;
printf("%d",*(int *)ptr);

printf("\n***************************");
printf("\nTotal Sectors:");
ptr=boot+0x0013;
printf("%d",*(int *)ptr);

printf("\n***************************");
printf("\nMedia descriptor byte:");
ptr=boot+0x0015;
printf("%2x",*(int *)ptr);

printf("\n***************************");
printf("\nNo of Sector per FAT:");
ptr=boot+0x0016;
printf("%d",*(int *)ptr);

printf("\n***************************");
printf("\nNo Sector per track:");
ptr=boot+0x0018;
printf("%d",*(int *)ptr);

printf("\n***************************");
printf("\nNo of heads:");
ptr=boot+0x001A;
printf("%d",*(int *)ptr);

getch();

}

/* OUTPUT


OME no =  , < v Y 5 I H C                                                       
*****************************                                                   
Byte per sector:512                                                             
***************************                                                     
Sector per cluster:1                                                            
***************************                                                     
No of FAT directory entry:2                                                     
***************************                                                     
No of Root directory entries:224                                                
***************************                                                     
Total Sectors:2880                                                              
***************************                                                     
Media descriptor byte:9f0                                                       
***************************                                                     
No of Sector per FAT:9                                                          
***************************                                                     
No Sector per track:18                                                          
***************************                                                     
No of heads:2

*/

read more

Write an ALP to simulate COPY command using PSP.

, by Prashant Gunjal

Write an ALP to simulate COPY command using PSP.

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

.MODEL SMALL
.DATA

        MSG1 DB 10,13,"INVALID FILENAME (NO 1) $"
        MSG2 DB 10,13,"INVALID FILENAME (NO 2) $"
        MSG3 DB 10,13,"ERROR IN OPENING FILE (NO 1) $"
        MSG4 DB 10,13,"ERROR IN WRITING (IE: FILE (NO 2)) $"
        MSG5 DB 10,13,"FILE ALREADY EXIST SO WRITING CONTENTS AT END OF FILE $" 
        MSG6 DB 10,13,"FILE 2 IS NOT PRESENT SO CREATING IT N WRITING DATA IN IT$"
        MSG7 DB 10,13,"   TASK COMPLETED SUCCESSFULLY$"

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

        CNT DW ?
        FH1 DW ?
        FH2 DW ?

.CODE
        MOV AX,@DATA
        MOV DS,AX

        MOV AH,62H  ;STARTING ADDRESS OF PSP
        INT 21H

        MOV ES,BX

        MOV DI,0082H  ;STARTING OFFSET OF PSP
        LEA SI,ARR1
        MOV BH,' '
        MOV CX,0000H

        CALL CHKVALID  ;CHK  NAME IS VALID OR NOT

        CMP CH,08H
        JBE N1
        DISP MSG1
        JMP EXIT
N1:     CMP CL,03H
        JE N2
        DISP MSG1
        JMP EXIT

N2:     MOV CX,0000H
        MOV BH,0DH
        LEA SI,ARR2
        INC DI

        CALL CHKVALID

        CMP CH,08H
        JBE N3
        DISP MSG2
        JMP EXIT
N3:     CMP CL,03H
        JE N4
        DISP MSG2
        JMP EXIT

;********OPEN FILE 1*************
N4:     MOV AH,3DH
        MOV AL,02H
        LEA DX,ARR1
        INT 21H

        MOV FH1,AX
        JNC N5
        DISP MSG3
        JMP EXIT

;******CALC SIZE OF FILE 1 N KEEP IT IN CNT*****
N5:     MOV AH,42H
        MOV AL,02H
        MOV BX,FH1
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

        MOV CNT,AX

;******SET FP ON STARTING OF FILE*********
        MOV AH,42H
        MOV AL,00H
        MOV BX,FH1
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

;****READ CONTENTS OF FILE 1 N KEEP IT IN ARR3****
        MOV AH,3FH
        MOV BX,FH1
        MOV CX,CNT
        LEA DX,ARR3
        INT 21H

        JC EXIT

;******CHK 2ND FILE ALREADY PRESENT OR NOT******
        MOV AH,3DH
        MOV AL,02H
        LEA DX,ARR2
        INT 21H

        MOV FH2,AX
        JC N6
        DISP MSG5

        ;** SET FP AT END OF FILE**

        MOV AH,42H
        MOV AL,02H
        MOV BX,FH2
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

        JMP N7

;*****CREATE FILE2 IF NOT PRESENT*********
N6:     MOV AH,3CH
        LEA DX,ARR2
        MOV CX,0000H
        INT 21H

        JC EXIT
        MOV FH2,AX
        DISP MSG6

;****WRITING CONTENTS IN FILE 2******
N7:     MOV AH,40H
        MOV BX,FH2
        MOV CX,CNT
        LEA DX,ARR3
        INT 21H

        JC EXIT
        DISP MSG7

EXIT:   MOV AH,4CH
        INT 21H

;********PROCEDURE CHECK VALID****************
CHKVALID PROC NEAR
C0:     MOV AH,ES:[DI]
        CMP AH,'.'
        JNE C1
        JMP C2

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

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

C3:     MOV AH,ES:[DI]
        CMP AH,BH
        JE R
        MOV [SI],AH
        INC CL
        INC SI
        INC DI
        JMP C3

R:      RET
ENDP
END
    

OUTPUT


C:\TASM>TASM P2
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   P2.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  472k


C:\TASM>TLINK P2
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\TASM>P2 P.TXT A.TXT

FILE ALREADY EXIST SO WRITING CONTENTS AT END OF FILE
   TASK COMPLETED SUCCESSFULLY
C:\TASM>
read more

Write an ALP to simulate TYPE command using PSP.

, by Prashant Gunjal

Write an 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 OPENED SUCCESSFULLY $"
        MSG2 DB 10,13,"FILE OPENING ERROR $"
        MSG3 DB 10,13,"RADED N CONTENTS ARE : $"
        MSG4 DB 10,13,"UNABLE TO READ FILE $"

        ARR1 DB 20 DUP(0)
        ARR2 DB 50 DUP(0)
        HANDLE DW ?
        CNT DW ?
.CODE
        MOV AX,@DATA
        MOV DS,AX

        MOV AH,62H   ;DOS FUN FOR GETTING ST ADD OF PSP
        INT 21H

        MOV ES,BX

        MOV DI,0082H ;STARTINF OFFSET OF PSP WHERE FILE NAME STORES
        LEA SI,ARR1

L1:     MOV AH,ES:[DI]
        CMP AH,0DH
        JE L2
        MOV [SI],AH
        INC SI
        INC DI
        JMP L1

;******OPEN FILE**********
L2:     MOV AH,3DH    
        MOV AL,02H
        LEA DX,ARR1
        INT 21H

        MOV HANDLE,AX
        JC L3
        DISP MSG1
        JMP L4

L3:     DISP MSG2
        JMP EXIT

;**********SET FILE POINTER AT END OF FILE FOR CALC SIZE OF FILE********

L4:     MOV AH,42H     
        MOV AL,02H
        MOV BX,HANDLE
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

        MOV CNT,AX
;**********SET FILE POINTER AT START OF FILE FOR  READ FILE********
        MOV AH,42H
        MOV AL,00H
        MOV BX,HANDLE
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

;******READING FILE**********
        MOV AH,3FH
        MOV BX,HANDLE
        MOV CX,CNT
        LEA DX,ARR2
        INT 21H

        JNC L5
        DISP MSG4
        JMP EXIT

L5:     DISP MSG3
        LEA SI,ARR2
;********DISPLAY CONTENTS*********
UP:     MOV DX,[SI]
        MOV AH,02H
        INT 21H
        INC SI
        DEC CX
        JNZ UP

EXIT:   MOV AH,4CH
        INT 21H
END

OUTPUT


C:\TASM>TASM P1
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   P1.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  474k

C:\TASM>TLINK P1
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International

C:\TASM>P1 B.TXT

FILE OPENED SUCCESSFULLY
RADED N CONTENTS ARE :  ||JAY SAI RAM|| ||JAY SAI RAM||
C:\TASM>

C:\TASM>P1

FILE OPENING ERROR
read more