System Level programming by c program


Important structure and union:


The header file dos.h defines two important structures and one union. They are:

1.
struct BYTEREGS {
unsigned char al, ah, bl, bh;
unsigned char cl, ch, dl, dh;
   };
2. struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si, di, cflag, flags;
   };
3. union REGS {
struct WORDREGS x;
struct BYTEREGS h;
  };

Note: Try to remember above structures and union.
There is also one very important function int86 () which has been defined in dos.h header file. It is general 8086 software interrupt interface. It will better to explain it by an example.

Write a c program to display mouse pointer?
Answer:

#include <dos.h>
#include <stdio.h>
void main()
{
union REGS i,o;
i.x.ax=1;
int86(0x33,&i,&o);
getch();
}

Explanation: To write such program you must have one interrupt table. Following table is only small part of interrupt table.
This table consists for column. They are:
(1)   Input
(2)   Output
(3)   Service number
(4)   Purpose

Now look at the first row of interrupt table. To show the mouse pointer assign ax equal to 1 i.e. service number while ax is define in the WORDREGS

struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si, di, cflag, flags;
};
And WORDRGS is define in the union REGS
union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};
So to access the structure member ax first declare a variable of REGS i.e.

REGS i, o;


Note: We generally use i for input and o for output

To access the ax write i.x.ax (We are using structure variable i because ax is input
(See in the interrupt table)

So to show mouse pointer assign the value of service number to it:

i.x.ax=1;

To provide this information to microprocessor
we use int86 function. It has three parameters

1. Interrupt number i.e.
0x33
2. union REGS *inputregiste i.e. &i
3. union REGS *outputregiste i.e. &o;
So write: int86 (0x33, &i, &o);

2 comments:

Anonymous said...

Hats off 2 u sir !!!..what a gr8 explanation

Saurav said...

great sir