406 Programming and Data Structures
{
ctoar nattfttfSJ;
in t age;
union r e s u lt p e r f;
} data;
c lrs c r O ;
printf ("Size of union; %dn",$izeof(data.perf));
printf ("Size of Structure: %dn", sizeoffdata));
i
Q.UXBJI;
Size of union: 2
Size of Structure : 19
Explanation Union contains two variables of data types in t & char respectively. The in t &
char requires 2 & 1 bytes respectively for storage. According to the theory the union reserves two
bytes because in t takes more space than char data type.
The structure res are defined immediately after union, which contains data type ch ar, i n t , &
union variable. The size of structure is printed which are nothing but sum of 15 bytes of char
array, two bytes o f in t and two bytes of union variable perf. Thus, the total size of structure is
19.
12.12 CALLING BIOS AND DOS SERVICES
We can access BIOS and DOS services through C language. Few simple examples are illustrated by
making use of BIOS and DOS services. The programmer does not have direct access to the CPU
registers. However, the C language provides an interface that allows the programmer to access any
BIOS or DOS service. The C language defines a union type called "REGS" and structure type called
"SREGS" in the file nDOS.H" which escorts the C compiler. These data types are used to pass
parameters to the CPU registers. In order to have access to these definitions the programmer has to
include "d o s . h" header file.
The union type "REGS" contains the CPU registers. These registers are used for holding the data
temporarily. The microprocessors 8086, 8088, 80186, 80286, and 80386 use a variety of registers for
arithmetic and logical operations. Also they are used to receive instructions and pass data to and
from memory.
The CPU registers are 16 bits in size. They are AX, BX, CX, DX, SI, Dl, and CFLAG, which is carry
flag. The size of CFLAG is also 16 bits. The structure that defines these 16 bits registers is called %x '.
The ' x f stands for a register pair. Size of each register is 8 bits. Thus, the size of pair registers ' x ' is
16 bits.
The union also allows us to refer 8 bit registers of above type processors. These 8 bits registers are
AL, AH, BL, BH, CL, CH, DL and DH. The structure that defines these 8 bit registers is called 'h'.
Here, 'h' stands for a half register i.e.8 bit register.
There are also segment registers in the above processors. The size of segment registers is 16 bits.
These segment registers DS, ES, CS and SS. The structure type "SREGS" defines these segment
registers.