Blogger news

Followers

Showing posts with label display. Show all posts
Showing posts with label display. Show all posts
Friday, February 21, 2014


File 1:  A file which contains Macro definition to read a character from keyboard. (give the file name as Read.asm)

INPUT   MACRO                                                      ; macro definition starts, with name of the macro as Input
MOV AH, 01H                                                           ; Service number (function no.) to read a character from the      
INT 21H                                                                                 ; Key board using DOS interrupt (21H) 
ENDM                                                                        ; terminate the macro definition.

File 2:  A file which contains Macro definition to display a character on the monitor. (give the file name as display.asm)

PRINT     MACRO                                                      ; macro definition starts, with name of the macro as Print    
MOV AH, 02H                                                            ; Service number (function no.) to display a character on 
INT 21H                                                                      ; the monitor using DOS interrupt (21H) 
ENDM                                                                         ; terminate the macro definition.
File 3:  A file which include the above 2 files created, in code segment and contains the macro expansion statements and other instructions to read string of characters until the carriage return is pressed and also display the string on the monitor.  (give the file name as 2a.asm)

ASSUME DS: DATA, CS: CODE
DATA SEGMENT                                                   ; start of data segment
STR    DB 100 DUP (' '), '$'                               ; To store input (user entered) string in array STR
MSG1 DB  'ENTER A SENTENCE : ‘,  '$'                     ; store the message enter a sentence in array MSG1
MSG2 DB 0DH, 0AH, 'ENTERED SENTENCE IS: ', '$'            ; store the message in array MSG2. 
DATA ENDS                                                             ; End of data segment

CODE SEGMENT                                                   ; start of code segment
INCLUDE READ.ASM                   ; including external file (read.asm)
INCLUDE DISPLAY.ASM             ; including external file (display.asm)
            START: MOV AX, DATA
MOV DS, AX                                                ; initializing data segment
            XOR AX, AX                                                ; clear AX register content
            MOV SI, OFFSET STR                            ; store the offset address of memory STR in SI register
            MOV DX, OFFSET MSG1                     ; store the offset address of memory MSG1 in DX
MOV AH, 09H                                   ; display the message stored in array memory MSG1
             INT 21H                                            ; using service no.09H, in DOS interrupt (21H)
AGAIN: INPUT                                               ; invoke macro (input) to read character from keyboard
            CMP AL, 0DH                                   ; compare end of string ie: whether the entered key is enter key
            JE DISP                                                                ; if yes terminate the read process and go to DISP to display
; the user entered string stored in array STR on the monitor.
            MOV [SI], AL                                                ; otherwise store character in array STR.
            INC SI                                                            ; increment the STR memory ptr by one 1 to point
; to the next memory location (ie: STR+1)
            JMP AGAIN                                                       ; go to AGAIN location  ,to  read the next character from keyboard                DISP :   MOV AL,0AH          
            MOV [SI], AL                                                ; store the ASCII code 0AH in last memory location of  STR array
            MOV DX, OFFSET MSG2                       ; store the offset of memory MSG2 in DX                                          MOV AH, 09H                                   ; display the message in MSG2 using 09H in DOS interrupt.
            INT 21H
            MOV SI, OFFSET  STR                             ; store offset address of STR in SI register (memory address
; of 1st location in STR array )
              BACK : MOV DL, [SI]                         ; take input string character stored in STR one by one.
            CMP DL, 0AH                                   ; compare with 0AH, to decide whether the last
; character of the sting in STR array is reached.
            JE STOP                                                              ; if equal go to STOP, and terminate the program.
            PRINT                                               ; otherwise invoke PRINT macro to display character on
; the output device (monitor)
            INC SI                                                            ; increment the memory ptr of STR array by one to get the
; next character from STR array to be displayed on the monitor
            JMP BACK                                                   ; go to BACK location, to display the next character on the monitor
STOP : MOV AH,4CH                                   ; terminate the program          
 INT 21H                                           
           
CODE ENDS                                                 ; end of code segment
             END START                                     ; end of program



Output:
   
D:\MASM> Masm 2a.asm;          or     (Masm 2a;)
D:\MASM> Link 2a.obj;                     (Link 2a;)
D:\MASM>2a.exe

Or
we can Debug the program using
D:\MASM> TD 2a.exe
Then press F7 to trace the program (line by line execution) or press F9 to run the program in one operation
Wednesday, November 13, 2013
Design,Develop and execute a program in C to implement a doubly linked list where each node consists of integers.The program should support the following operations:
 1.Create a doubly linked list by adding each node at the front.
2.Insert a new node to the left of the node whose key value is read as an input.
3.Delete the node of a given data if it’s found, otherwise display appropriate message
4.Display the contents of the list.


#include<stdio.h>
 #include<conio.h>
 #include<stdlib.h>

 typedef struct node *NODE;
 struct node
 {
   int info;
   NODE left,right;
 };

 NODE first;
 int empty();
 void create();
 void insert();
 void delete();
 void display();

 NODE getnode()
 {
   return((struct node*)malloc(sizeof(struct node)));
 }

 int empty()
 {
  return(first==NULL?1:0);
 }

 void create()
 {
  NODE new;
  int ch;
  first=NULL;

  do
  {
  new=getnode();
  printf("\n enter element to be inserted:");
  scanf("%d",&new->info);
  new->left=new->right=NULL;
  if(first==NULL)
  {
    first=new;
  }
  else
  {
    new->right=first;
    first->left=new;
    first=new;
  }
  printf("\n continue?1\0");
  scanf("%d",&ch);
 }
 while(ch!=0);
}

void insert()
{
 NODE new,curr,prev;
 int x,f=0;
 printf("\n enter the key value of a node\n");
 scanf("%d",&x);
 if(x==first->info)
 {
  new=getnode();
  printf("\n enter a value for new node to be inserted:\n");
  scanf("%d",&new->info);
  new->left=new->right=NULL;
  new->right=first;
  first=new;
 }
 else
 {
  curr=first->right;
  while(curr!=NULL)
  {
   if(x==curr->info)
   {
    f=1;
    break;
   }
   curr=curr->right;
 }
 if(f)
 {
  new=getnode();
  printf("\n enter a value to be inserted \n");
  scanf("%d",&new->info);
  new->left=new->right=NULL;
  prev=curr->left;
  new->right=curr;
  curr->left=new;
  prev->right=new;
  new->left=prev;
 }
 else
 {
 printf("\n invalid key value \n");
}
}
}
void delete()
{
 NODE curr,prev;
 int f=0,x;
 printf("\n enter info value of node you want to delete \n");
 scanf("%d",&x);
 if(x==first->info)
 {
  curr=first;
  first=first->right;
  first->left=NULL;
  printf("\n deleted item %d",curr->info);
  free(curr);
 }
 else
 {
  curr=first->right;
  while(curr!=NULL)
  {
   if(x==curr->info)
   {
    f=1;
    break;
  }
  curr=curr->right;
  }
  if(f)
  {
  prev=curr->left;
  prev->right=curr->right;
  curr->right->left=prev;
  free(curr);
 }
 else
 printf("\n not valid node!! not found \n");
}
}


void display()
{
 NODE curr;
 printf("\n elements of the list \n");
 printf("\n NULL<-");
 for(curr=first;curr!=NULL;curr=curr->right)
 {
  printf("%d<-->",curr->info);
 }
 printf("NULL \n");
}
void main()
{
 int ch;
 clrscr();
 printf("\n \n doubly linked list will be created \n");
 create();
 display();
 printf("\n\n doubly linked list will be created \n");
 printf("\t1->insert\n");
 printf("\t2->delete\n");
 printf("\t3->display\n");
 printf("\t4->exit\n");
 while(1)
 {
  printf("enter your choice \n");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:
     if(first==NULL)
     {
     printf("empty list \n");
     printf("insert left not possible \n");
   }
   else
   {
   insert();
   display();
   }
   break;
  case 2:
    if(empty())
      printf("\n empty list \n");
    else
    {
     delete();
     if(!empty())
     display();
    }
    break;
    case 3:
    if(empty())
    printf("\n empty list \n");
    else
    {
    display();
    }
    break;
    case 4:
      exit(0);
    default:
    printf("\n invalid choice!!");
  }
 }
  getch();
 }



Program end