Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!elroy!mahendo!jplgodo!wlbr!etn-rad!jru From: jru@etn-rad.UUCP (John Unekis) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Accessing data from an interrupt handler Message-ID: <291@etn-rad.UUCP> Date: Fri, 9-Oct-87 13:45:43 EDT Article-I.D.: etn-rad.291 Posted: Fri Oct 9 13:45:43 1987 Date-Received: Sun, 11-Oct-87 17:41:28 EDT References: <330@picuxa.UUCP> Reply-To: jru@etn-rad.UUCP (John Unekis) Organization: Eaton Inc. IMSD, Westlake Village, CA Lines: 35 Xref: mnetor comp.sys.ibm.pc:8886 comp.lang.c:4808 In article <330@picuxa.UUCP> gp@picuxa.UUCP (Greg Pasquariello X1190) writes: >I ran into a small problem today, and I was wondering if anyone could >shed some light on it. I wrote a test program in MSC 4.0 that will ... >tell me why the variable is incremented when the routine is used as a called >function, but not when the routine is used as an interrupt routine? Remember that addresses on the intel processor are composed of two parts, a segment, which comes from one of the segment registers, and an offset which may be a register or part of the instruction. When you use the small model compiler it is assumed that all of your data fits in one segment, and the data segment(DS) register is loaded once at the start of your program and never changed. When you call your routine as a subroutine, the data segment register is properly set up, and your routine accesses the increment variable location as an offset from the DS register. When you come into your routine off an interrupt, the data segment is set up to whatever DOS left it at before jumping to your routine. When you try to increment your variable as an offset from the data segment you are actually incrementing some location in the DOS data space(bad idea). In order to find the variable that you really want to increment, you will have to have a separate entry point to your routine that will save the user mode data segment register in a memory loacation in the code portion of your interrupt service routine. Then when you catch an interrupt, you should push the DS on the stack, retreive the user mode DS from the location in your code segment, increment your variable at the correct location, then pop the DOS mode DS back off the stack. BTW: This is why Motorola 680X0 processors are so popular for real - time applications that require interrupt handling and data sharing, NO SEGMENTS. An address is an address is an address. The propagation of this archaic segmented architecture into Intel's state-of-the-art 80X86 chips in order to preserve IBM PC compatibility reminds me of an old joke: Intel to IBM : Mommy, Mommy, why do I keep walking in circles? IBM to Intel : Shut up or I'll nail your other foot to the floor.