home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_01 / memsize0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-22  |  1.1 KB  |  40 lines

  1. /* MEMSIZE0.C - From page 323 of "Microsoft C Programming for   */
  2. /* the IBM" by Robert Lafore. It uses a ROM BIOS return to print*/
  3. /* the size of memory in a machine.                             */
  4. /****************************************************************/
  5.  
  6. #define MEM 0x12           /*BIOS interrupt number*/
  7.  
  8. main()
  9. {
  10. struct WORDREGS {          /*registers as 16 bit words*/
  11.    unsigned int ax;
  12.    unsigned int bx;
  13.    unsigned int cx;
  14.    unsigned int dx;
  15.    unsigned int si;
  16.    unsigned int di;
  17.    unsigned int flags;
  18. };
  19.  
  20. struct BYTEREGS {          /*registers as 8 bit bytes*/
  21.    unsigned char al, ah;
  22.    unsigned char bl, bh;
  23.    unsigned char cl, ch;
  24.    unsigned char dl, dh;
  25. };
  26.  
  27. union REGS {               /*either bytes or words*/
  28.    struct WORDREGS x;
  29.    struct BYTEREGS h;
  30. };
  31.  
  32. union REGS regs;           /*regs to be type union REGS*/
  33. unsigned int size;
  34.  
  35.    int86(MEM, ®s, ®s);  /*call memory interrupt*/
  36.    size = regs.x.ax;          /*get value from AX register*/
  37.    printf("\nMemory size is %dK bytes\n", size);
  38. }
  39.  
  40.