Thread: storage size of regs is unkown

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    28

    storage size of regs is unkown

    Hi, i am trying to learn to program in c but i keep getting stuck on this error, "storage size of regs isn't known". I am using the latest release of Bloodshed Dev-C++. I've made sure that i checked that the program is being compiled as a c file and not cpp and i checked to make sure that dos.h exists. but other than that could someone please help me figure this out. I've included the sample source from the book i'm learning from:

    Code:
    #include <stdio.h>
    #include <dos.h>
    
    main()
    {
      int major,minor;
      union REGS regs;
      
      regs.h.al=1;
      regs.h.ah=0x30;
      int86(0x21,&regs,&regs);
      major=regs.h.al;
      minor=regs.h.ah;
      printf("this is does version %i, release %i\n",major,minor);
      
    }

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    go into your dos.h and see if you can find a REGS struct. I tried doing your program with both Visual C++ and DJGPP(GNU). DJGPP's worked, and VC's didn't. I looked in each compiler's dos.h, and in DJGPP's I found the REGS struct. If you can't find the REGS struct you can try downloading dos.h off of http://www.djdelorie.com/DJGPP just go to the zip picker.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Short answer - you're using a non-DOS compiler to compile a DOS program - never going to happen

    > can try downloading dos.h off of http://www.djdelorie.com/DJGPP just go to the zip picker.
    Read the FAQ to find out why this is SO not going to work.

    Downloading the whole of DJGPP and using that compiler might be a better option, but IMO, you've got no business messing with interrupts whilst " i am trying to learn to program in c"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Thanks, i guess i assumed since dev c++ had the dos.h file then it would work but i guess they can be different from one compiler to the next. I am not trying to learn interupts, yet, just trying to make sure i understand what is being taught in this book. Thanks for the help.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > it would work but i guess they can be different from one compiler to the next
    The only time this is true is if you stick to the 15 or so files which are part of the ANSI-C standard.
    http://www-ccs.ucsd.edu/c/

    When you start using any other header files, you're tying yourself to a specific implementation and things get more interesting when you try and compile code for platform X on platform Y

    You can learn an awful lot by sticking to the standard stuff, because you can do all the things like lists, trees, etc within this environment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Most things that can be done with regs can be done using inline assembler.

    You can code your own function that will save the registers, execute the interrupt and then return.

    Code:
    typedef unsigned char BYTE;
    #ifdef _BITS16_
      typedef unsigned int WORD;
      typedef unsigned long DWORD;
      typedef double QWORD;
    #elseif
      typedef unsigned short WORD;
      typedef unsigned int DWORD;
      typedef unsigned long QWORD;
    #endif
    
    struct byteregs
    {
      BYTE ah;
      BYTE al;
      BYTE bh;
      BYTE bl;
      BYTE ch;
      BYTE cl;
      BYTE dh;
      BYTE dl;
    };
    
    struct wordregs
    {
      WORD ax;
      WORD bx;
      WORD cx;
      WORD dx;
      WORD bp;
      WORD sp;
      WORD si;
      WORD di;
    };
    
    struct dwordregs
    {
      DWORD eax;
      DWORD ebx;
      DWORD ecx;
      DWORD edx;
      DWORD ebp;
      DWORD esp;
      DWORD edi;
      DWORD esi;
    
    };
    
    struct REGS
    {
      byteregs h;
      wordregs x;       //not really used
      dwordregs ex;
    };
    
    struct SREGS
    {
      DWORD ds;
      DWORD es;
      DWORD gs;
      DWORD fs;
    };
    
    
    
    void int86(int interruptnum,REGS input,REGS output)
    {
      DWORD r_eax=input.ex.eax;
      DWORD r_ebx=input.ex.ebx;
      DWORD r_ecx=input.ex.ecx;
      DWORD r_edx=input.ex.edx;
      DWORD r_ebp=input.ex.ebp;
      DWORD r_esp=input.ex.esp;
      DWORD r_edi=input.ex.edi;
      DWORD r_esi=input.ex.esi;
    
      asm {
        mov eax,[r_eax]
        mov ebx,[r_ebx]
        mov ecx,[r_ecx]
        mov edx,[r_edx]
        mov ebp,[r_ebp]
        mov esp,[r_esp]
        mov edi,[r_edi]
        mov esi,[r_esi]
    
        int [interruptnum]
        
        mov [r_eax],eax
        mov [r_ebx],ebx
        mov [r_ecx],ecx
        mov [r_edx],edx
        mov [r_ebp],ebp
        mov [r_esp],esp
        mov [r_edi],edi
       }
    
        output.ex.eax=r_eax;
        output.ex.ebx=r_ebx;
        output.ex.ecx=r_ecx;
        output.ex.edx=r_edx;
        output.ex.ebp=r_ebp;
        output.ex.esp=r_esp;
        output.ex.edi=r_edi;
        output.ex.esi=r_esi;
    }
    
    void int86(int interruptnum,REGS input,REGS output,SREGS sinput,SREGS soutput)
    {
      DWORD r_eax=input.ex.eax;
      DWORD r_ebx=input.ex.ebx;
      DWORD r_ecx=input.ex.ecx;
      DWORD r_edx=input.ex.edx;
      DWORD r_ebp=input.ex.ebp;
      DWORD r_esp=input.ex.esp;
      DWORD r_edi=input.ex.edi;
      DWORD r_esi=input.ex.esi;
      DWORD sr_ds=sinput.ds;
      DWORD sr_es=sinput.es;
      DWORD sr_fs=sinput.fs;
      DWORD sr_gs=sinput.gs;
    
    
      asm {
        push ds
    
        mov eax,[sr_ds]
        mov ds,eax
        mov eax,[sr_es]
        mov es,eax
        mov eax,[sr_fs]
        mov fs,eax
        mov eax,[sr_gs]
        mov gs,eax
        mov eax,[r_eax]
        mov ebx,[r_ebx]
        mov ecx,[r_ecx]
        mov edx,[r_edx]
        mov ebp,[r_ebp]
        mov esp,[r_esp]
        mov edi,[r_edi]
        mov esi,[r_esi]
    
        int [interruptnum]
        
        mov [r_eax],eax
        mov [r_ebx],ebx
        mov [r_ecx],ecx
        mov [r_edx],edx
        mov [r_ebp],ebp
        mov [r_esp],esp
        mov [r_edi],edi
        mov [sr_ds],ds
        mov [sr_es],es
        mov [sr_fs],fs
        mov [sr_gs],gs
       
        pop ds
       }
    
        output.ex.eax=r_eax;
        output.ex.ebx=r_ebx;
        output.ex.ecx=r_ecx;
        output.ex.edx=r_edx;
        output.ex.ebp=r_ebp;
        output.ex.esp=r_esp;
        output.ex.edi=r_edi;
        output.ex.esi=r_esi;
        soutput.ds=sr_ds;
        soutput.es=sr_es;
        soutput.fs=sr_fs;
        soutput.gs=sr_gs;
    
    }
    Some inline assemblers do not allow the use of 32-bit registers even though they allow 32-bit code. Also some inline assemblers do not allow access to the fs and gs segment registers even though they are valid segment registers.

    Note that I did not include the ability to set the high and low bytes of the explicit return registers. This can be done easily by loading ah,al,bh,bl,ch,cl,dh, and dl individually which will also load ax,cx,bx,dx. Since my code uses 32-bit simply put the value you want in eax,ebx,ecx, and edx. It will still work since the value will be in the low order bytes.

    There are faster ways than this but this was the most straightforward.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. How do you use variable to initialize array size?
    By yougene in forum C Programming
    Replies: 11
    Last Post: 09-04-2007, 02:50 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 08:03 PM