Saturday, 9 August 2014

Hardware program to inverse the status of caps, num and scroll lock

This is a hardware program to inverse the status of the caps, num and scroll lock. If you have any doubts please let me know.

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

int main()
{
int c,n,s;
int far *p=(int far *)0x417;
int far *q=(int far *)0x418;
char text[50];
union REGS in, out;
clrscr();

c=*p&0x40;
s=*p&0x10;
n=*p&0x20;

if (c==0x40)
                        printf("\nCaps lock is ON");
else
                        printf("\nCaps lock is OFF");

if(n==0x20)
                        printf("\nNum lock is OFF");
else
                        printf("\nNum lock is ON");

if(s==0x10)
                        printf("\nScroll lock is ON");
else
                        printf("\nScroll lock is OFF");
printf("\nText before toggle: ");
gets(text);

*p=*p^0x70;
*q=*q^0x70;

printf("\nTOGGLE\n");

c=*p&0x40;
s=*p&0x10;
n=*p&0x20;

if (c==0x40)
                        printf("\nCaps lock is ON");
else
                        printf("\nCaps lock is OFF");

if(n==0x20)
                        printf("\nNum lock is OFF");
else
                        printf("\nNum lock is ON");

if(s==0x10)
                        printf("\nScroll lock is ON");
else
                        printf("\nScroll lock is OFF");

printf("\nText after toggle: ");
gets(text);
printf("\n Press any key to exit");
getch();

return 0;

}

Hardware program to implement the filling of a rectangle with a click

This is a hardware program to implement the filling of a rectangle on a click. If you have any doubts, please let me know. 

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

int main(void)
{
    clrscr();
   int gdriver = DETECT, gmode;
   int left, top, right, bottom,c,poly[8],x,y;
   union REGS in,out;
   initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi ");
   left = getmaxx() / 2 - 50;
   top = getmaxy() / 2 - 50;
   right = getmaxx() / 2 + 50;
   bottom = getmaxy() / 2 + 50;
   rectangle(left,top,right,bottom);
   in.x.ax=7;
   in.x.cx=left;
   in.x.dx=right;
   int86(0x33,&in,&out);
   in.x.ax=8;
   in.x.cx=top;
   in.x.dx=bottom;
   int86(0x33,&in,&out);
   in.x.ax=1;
   int86(0x33,&in,&out);
    poly[0]=left;
    poly[1]=top;
    poly[2]=left+100;
    poly[3]=top;
    poly[4]=right;
    poly[5]=bottom;
    poly[6]=right-100;
    poly[7]=bottom;
    printf("BUTTON STATUS");
    while(!kbhit())
    {
      in.x.ax=3;
      int86(0x33,&in,&out);
      c=out.x.bx;
      gotoxy(2,2);
      switch(c)
      {
      case 0:
                 break;
      case 1:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,15);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nLEFT  PRESS");
                 break;
      case 2:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,0);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nRIGHT PRESS");
                 break;
      }
      gotoxy(2,4);
      printf("\nPress any key to exit");
    }
    in.x.ax=0;
    int86(0x33,&in,&out);
    getch();
    closegraph();
    return 0;
}





Hardware lab program for ascii and scan values of a key

This is a hardware lab program to obtain the scan code and ascii code of a key. If you have any doubts, please let me know.


DEVELOPMENT:

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
            int ac,sc;
            union REGS in,out;
            do
{

                        clrscr();
                        printf("Enter a key");
                        in.x.ax=0;
                        int86(0x16,&in,&out);
                        sc=out.h.ah;
                        ac=out.h.al;
                        printf("\nKey: %c",ac);
                        printf("\n Scan code is:%d",sc);
                        printf("\n Ascii code is :%d",ac);
                        printf("\nPress any key to continue and 'e' to exit!\n");

}while(getch()!='e');

 }



Hardware lab program for Mouse co-ordinates as well as status

This is a C program to implement mouse co-ordinates as well as status of button click in the hardware lab.
If you have any doubts, please let me know.

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
     int x,y , z,x1,y1,z1;
     union REGS in,out;
     in.x.ax=1;
     int86(0x33,&in,&out);
     in.x.ax=3;
     int86(0x33,&in,&out);
     x1=out.x.cx;
     y1=out.x.dx;
     z1=out.x.bx;
    do
    {
        do
        {
              in.x.ax=1;
              int86(0x33,&in,&out);
              in.x.ax=3;
              int86(0x33,&in,&out);
              x=out.x.cx;
              y=out.x.dx;
              z=out.x.bx;
        }while((x==x1)&&(y==y1)&&(z==z1));
            clrscr();
            printf("MOUSE COORDINATES:");
            printf("\nx coordinate:%d\t ",x1);
            printf("\ny coordinate:%d\t ",y1);
            printf("\n\nBUTTON STATUS");
            switch(z1)
            {
                 case 0: printf("\nNo press\n");
                        break;
                 case 1:printf("\nLeft press\n");
                        break;
                 case 2:printf("\nRight press\n");
                        break;
                 case 3:printf("\nBoth press\n");
                break;
         }
         x1=x;
         y1=y;
             z1=z;
             printf("\n\nPress any key to exit..");
     }while(!kbhit());
     in.x.ax=2;
     int86(0x33,&in,&out);
}









































8086 program to count the number of vowels in a string

This is an 8086 program to count the number of vowels in a string. If you have any doubts, please let me know.

.MODEL SMALL
.DATA
inp db 0ah,0dh,'enter the string: ','$'
msg db 0ah,0dh,'the number of vowels: ','$'
vowel db 'a','A','e','E','i','I','o','O','u','U','$'
databuf db 100,0,100 dup('$')
.code
START:
mov ax,@data
mov ds,ax

lea dx,inp
mov ah,09h
int 21h

lea dx,databuf
mov ah,0ah
int 21h
mov si,dx

lea dx,msg
mov ah,09h
int 21h
       
mov bl,00h
check:  lea di,vowel
mov cx,000ah
mov al,[si]
cont:
cmp al,[di]
je found
inc di
loop cont
jmp next
found:  inc bl
next:   inc si
cmp databuf[si],0ah
jne check
mov dl,bl
add dl,30h
mov ah,02h
int 21h


.EXIT
END START

8086 program to check whether a string is a palindrome or not

This is an 8086 program to check whether a string is a palindrome or not. If you have any doubts, please let me know.

.MODEL SMALL
.DATA
MSG DB 'ENTER A STRING:','$'
INP DB 100,0,100 DUP('$')
MSG2 DB 0AH, 0DH,'PALINDROME','$'
MSG3 DB 0AH, 0DH,'NOT A PALINDROME','$'
.CODE
START:
MOV AX,@DATA
MOV DS,AX

LEA DX,MSG
MOV AH,09H
INT 21H

LEA DX,INP
MOV AH,0AH
INT 21H

LEA SI,INP
LEA DI,INP
         MOV CX,0000H

CONT:   MOV AL,[DI+02H]
CMP AL,0DH
JE L1
INC CX
INC DI
JMP CONT

L1: DEC DI

L2:    MOV AL,[DI+02H]
    CMP [SI+02H],AL
    JNE NP
    INC SI
    DEC DI
    LOOP L2  

P:  LEA DX,MSG2
    MOV AH,09H
    JMP LAST
NP: LEA DX,MSG3
    MOV AH,09H
LAST:INT 21H
   
.EXIT
END START



































8086 program to print out the multiplication table

This is an 8086 program to print out the multiplication table of a number. If you have any doubts, please let me know.
.MODEL SMALL
.DATA
MSG DB 0AH,0DH,'ENTER A NUMBER: ',0AH,'$'
NEW DB 0AH,0DH,24H
INP DB 10,0,10 DUP('$')
MULT DB 01H
MSG2 DB 0AH,0DH,'MULTIPLICATION TABLE:',0AH,'$'
.CODE
START:
MOV AX,@DATA
MOV DS,AX

LEA DX,MSG
MOV AH,09H
INT 21H

LEA DX,INP
MOV AH,0AH
INT 21H

ADD DX,02H
MOV SI,DX

LEA DX,MSG2
MOV AH,09H
INT 21H


LEA DI,MULT

MOV AH,00H
MOV CX,000AH
INC DI
MOV [DI],CX
DEC DI
MOV BL,[DI]
MOV BH,00H

AGAIN:
MOV [DI],BL
INC DI
MOV [DI],CL
DEC DI

MOV DL,[SI]
MOV AH,02H
INT 21H

MOV DL,'*'
MOV AH,02H
INT 21H

MOV DL,[DI]
CMP DL,0AH
JNE TEN
MOV DL,31H
MOV AH,02H
INT 21H
MOV DL,30H
MOV AH,02H
INT 21H

JMP EQUAL
TEN:ADD DL,30H
MOV AH,02H
INT 21H

EQUAL:MOV DL,'='
MOV AH,02H
INT 21H

MOV AL,[SI]
SUB AL,30H
MOV AH,00H
MUL BX
CALL DISPLAY
MOV BL,[DI]
MOV BH,00H
INC BX
INC DI
MOV CL,[DI]
MOV CH,00H
DEC DI
LOOP AGAIN
.EXIT

DISPLAY PROC
   MOV BX, 000AH  
   MOV DX, 0000H  
   MOV CX, 0000H  
   
L1:  MOV DX, 0000H  
   DIV BX    
   PUSH DX    
   INC CX    
   CMP AX, 0000H  
   JNE L1  
   
L2:  POP DX    
   ADD DX, 30H    
   MOV AH, 02H    
   INT 21H    
   LOOP L2
   LEA DX,NEW
   MOV AH,09H
   INT 21H
   RET      
DISPLAY ENDP
END START;