Thread: dos programming

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

    dos programming

    I got my self a 16bit compiler so I can compile to dos. In the header <dos.h> it has a union called REGS. May someone please give me more information on this union?

    Thanx in advance!

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It is used in conjuction with the int86() and int86X() functions that generate software interrupts.

  3. #3
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226
    This union has members in which you can store the values of registers that you need before calling an interrupt through int86() etc...

    The int86() function:

    1. PUSHes the current values of the CPU registers to some other temporary space....

    2. fills in the actual registers with the values provided (i.e. the members of the UNION provided by you)...

    3. calls the interrupt.....

    4. changes the members of the UNION provided by you with the new CPU register values (Caused by the function performed by your interrupt call)....

    5. and POPs up the previous values into the actual CPU register (i.e. cleans up its mess) before returning....

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    There really is no mess to clean up unless EDI ESI, EBP, ESP, or DS have been altered by the interrupt handler. Otherwise int86() is simply a function that auto-saves the values of the registers. The only requirement of interrupt handlers is that they leave the registers as they were prior to entering the handler. Since most well-behaved handlers do this, int86() is overkill. But C and the IDE have a tendency to alter the registers so int86() and int86x() are simply guaranteeing that the software interrupt will work and the register values will be correct.

    In pure assembly there really is no need to save every register's value on the stack so in some instances int86() and int86x() are overkill.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Bubba
    There really is no mess to clean up unless EDI ESI, EBP, ESP, or DS have been altered by the interrupt handler. Otherwise int86() is simply a function that auto-saves the values of the registers. The only requirement of interrupt handlers is that they leave the registers as they were prior to entering the handler. Since most well-behaved handlers do this, int86() is overkill. But C and the IDE have a tendency to alter the registers so int86() and int86x() are simply guaranteeing that the software interrupt will work and the register values will be correct.

    In pure assembly there really is no need to save every register's value on the stack so in some instances int86() and int86x() are overkill.
    Hmmm, so if "int86() and int86x() are overkill," what function would you suggest instead of int86 and int86X?

    Also, have you ever heard of reentrant code? This is something that has to be considered when writing multi-tasking systems with common shared routines.

    If a common shared function is interrupted by a higher priority task while it's processing and the same function is called in the new task, the registers get changed. When the original task continues, the registers no longer contain the values it had. Hence, the routine must save and restore the registers when it runs.

    This is sometihing I had to consider seriously in many systems I had to design.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Since a task switch will auto-save the state of the CPU then doing it manually would be overkill. The only rule is that if you alter registers other than the explicit return value registers you should save the previous values and restore them before returning from your function and/or interrupt handler.

    For instance if you alter DS you would push it prior to changing what it points to. Upon completion you would pop it off the stack to restore it.

    But if you alter ES you could probably get away w/o saving it. I recommend that if you alter EDI or ESI that you should probably save those as well. However, it is pointless to save EAX EBX ECX and EDX even acrossed a task switch - beings that the TSS will save it for you.

    If you think I don't understand re-entrant code then check some of my earlier posts and one on the C board concerning DOS interrupt handlers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 09:08 PM
  2. winver, winminor, winmajor can it be found from dos?
    By ronin in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-02-2002, 10:32 AM
  3. real mode dos & win dos
    By scott27349 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-19-2002, 06:15 AM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 07:14 PM