Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven!uflorida!reef.cis.ufl.edu!jdb From: jdb@reef.cis.ufl.edu (Brian K. W. Hook) Newsgroups: comp.lang.c Subject: Re: Direct memory addressing in TURBO C/C++ Message-ID: <27215@uflorida.cis.ufl.EDU> Date: 28 Feb 91 18:58:14 GMT References: Sender: news@uflorida.cis.ufl.EDU Distribution: comp Organization: UF CIS Dept. Lines: 62 In article morgan@chaos.cs.brandeis.edu (Dylan Kaufman) writes: |>Hi, |> |>I have been trying to figure out how to do direct memory addressing in |>C++. The addressing I am thinking about in particular is done with |>the keyword absolute in TURBO Pascal. For example, to turn the Num |>Lock key off : |> |>var |> Key_Status_Bit : word absolute $0040:$0017; |>begin |> Key_Status_Bits := (Key_Status_Bits and $DF); |>end. |> |>I guess what I'm trying to ask is what the C equivalent (if any) for |>absolute is... Number one: While I am a big proponent of liberal cross posting WHEN APPROPRIATE, I do believe this belongs on comp.os.msdos.programmer so please redirect all followups accordingly. Number two: What you need is the FAR keyword of MS or the far keyword of Borland. In a nutshell, all pointers that you declare assume that you are using the "near" heap, ie. that you are not addressing outside of your data segment (if you are using a small memory model -- small or tiny ). While this is a gross oversimplification and generalization, it is the quickest way possible to explain this. The area that you are trying to access is given in the segment starting at 0000. Depending on your memory model, a pointer that you define will likely default to pointing in your current data segment. You don't want this. Thus declare a far pointer, let's assume to a word (usigned int). For most purposes, all a far pointer does is let you explicity state which segment that you wish your pointer to offset from, i.e. a complete 20-bit IBM PC address vs. a 16-bit segment address. unsigned int far *data; Now point this to the correct location: data=(unsigned char far *)MK_FP(0x0040,0x0017); For more info on MK_FP (make far pointer) please read the Turbo C++ help on this. That's all there is to it. Data is pointing there, so you can just say *data=*data&0xDF; Or something like that. Warnings: You MUST be using TC++ keywords (this is far from ANSI compatible). You MUST include DOS.H (which defines the MK_FP macro) And remember, please follow up to comp.os.msdos.programmer Brian