[comp.lang.c] ACCESS REGISTERS FROM TURBO C??

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/14/90)

This question might be silly to some of you. How can I directly access
registers from Turbo C?

hutzley@bigq.dec.com (Steve Hutzley) (11/15/90)

In article <11475@j.cc.purdue.edu>, zhou@brazil.psych.purdue.edu (Albert Zhou) writes...
>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

Look at <union REGPACK....>

        example

    void your_funct(int a, int b)
      {
      union REGS in, out;

      r.h.ah = a;
      r.x.bx = b;
      int86(0x10, &in, &out);  /* call int 10, video */   
      }


      r.x.   = 16 bits (AX,BX,CX.....)
      r.h.   =  8 bits (either AH, AL)

        ANY QUESTIONS?
    Steve

gordon@osiris.cso.uiuc.edu (John Gordon) (11/15/90)

	Well, in one of the .h files (dos.h? io.h?) there is a structure
or a union called REGS.  Check it out.

c164-bd@portia.uucp (John D. Mitchell) (11/15/90)

In article <11475@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

On page 264 of the TC++ v1.0 Programmer's Guide is a section titled
"Pseudovariables, inline assembly, and interrupt functions".
You want the first part about pseudovariables.  Basically, _AH, _BX,
etc.

John
johnm@cory.Berkeley.EDU

c164-bd@cinna.uucp (John D. Mitchell) (11/15/90)

In article <2024@mountn.dec.com> hutzley@bigq.dec.com (Steve Hutzley) writes:
>
>In article <11475@j.cc.purdue.edu>, zhou@brazil.psych.purdue.edu (Albert Zhou) writes...
>>This question might be silly to some of you. How can I directly access
							 ^^^^^^^^
>>registers from Turbo C?
>
>Look at <union REGPACK....>
>
>        example  [deleted]

If the original poster wanted *direct* access then see my previous
posting.

The REGPACK union is really only useful for the DOS intXX() interrupt
interface functions.  The incur a lot of overhead due to (usually)
excessive copying of the union to the actual registers prior to the
int call and then copying the registers into the union after the call.
The plus is that quite a few DOS compilers support this feature in
basically the exact same way.  The inline assembly and pseudovariable
capabilities of TC will generate (unportable but) faster, smaller code.

Good luck,
	John Mitchell
	johnm@cory.Berkeley.EDU

mclaren (Gavin McLaren) (11/15/90)

In article <11475@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

Yes, there are two ways.

The first is to program in assembly language.  Look up the appropriate
#--- preprocessor command to do this.  Turbo C won't be able to compile this
from the integrated environment - use TCC.

The simpler way is to use the Turbo C predefined variables for every register.
Off the top of my head, they go something like:

_AH
_BL
_DS

etc.  Just use them like you would any other variable.  Of cource, code
written this way is unlikely to be portable, but you knew that, didn't you :)

You may have to include some special include file.  My best advice is RTFM.

--Gavin McLaren
...!uunet!van-bc!mdivax1!mclaren

epames@eos.ericsson.se (Michael Salmon) (11/15/90)

In article <11475@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

Registers can be accessed as pseudo-variables with names like _DS
or something similar. RTFM.

Michael Salmon
L.M.Ericsson
Stockholm

djm@castle.ed.ac.uk (D Murphy) (11/15/90)

In article <11475@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu 
(Albert Zhou) writes:
>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

There are pseudo variables _AX ... _DX, _CS, _DS, ES, _SS which you can
use to directly assign and read the registers. There is information about
them in the online help.

Murff....

al198723@mtecv2.mty.itesm.mx (SANCHEZ P JESUS E) (11/21/90)

zhou@brazil.psych.purdue.edu (Albert Zhou) writes:

>This question might be silly to some of you. How can I directly access
>registers from Turbo C?

You can access the pseudovariables:
	_AX, _BX, _CX, _DX, _SI, _DI, _BP, _SP, _ES
(I'm not sure about _CS, _DS, _SS)

They correspond to the 8086 registers, and you may access them freely
in your program.

Eugenio Sanchez
al198723@mtecv2.mty.itesm.mx
"Si os dan papel pautado, escribid por el otro lado" 
	Juan Ramon Jimenez

ge@wn3.sci.kun.nl (Ge' Weijers) (12/03/90)

al198723@mtecv2.mty.itesm.mx (SANCHEZ P JESUS E) writes:

>You can access the pseudovariables:
>	_AX, _BX, _CX, _DX, _SI, _DI, _BP, _SP, _ES
>(I'm not sure about _CS, _DS, _SS)

>They correspond to the 8086 registers, and you may access them freely
>in your program.

Yeah, like in _SP = 0x4561;  There is more than enough rope to hang
yourself here. Caveat programmer.

Ge' Weijers
--
Ge' Weijers                                    Internet/UUCP: ge@cs.kun.nl
Faculty of Mathematics and Computer Science,   (uunet.uu.net!cs.kun.nl!ge)
University of Nijmegen, Toernooiveld 1         
6525 ED Nijmegen, the Netherlands              tel. +3180652483 (UTC-2)

hagins@gamecock.rtp.dg.com (Jody Hagins) (12/06/90)

In article <2526@wn1.sci.kun.nl>, ge@wn3.sci.kun.nl (Ge' Weijers) writes:
|> al198723@mtecv2.mty.itesm.mx (SANCHEZ P JESUS E) writes:
|> 
|> >You can access the pseudovariables:
|> >	_AX, _BX, _CX, _DX, _SI, _DI, _BP, _SP, _ES
|> >(I'm not sure about _CS, _DS, _SS)
|> 
|> >They correspond to the 8086 registers, and you may access them freely
|> >in your program.
|> 
|> Yeah, like in _SP = 0x4561;  There is more than enough rope to hang
|> yourself here. Caveat programmer.



But isn't that part of the fun?  Finding out just how much rope
you can give yourself without swinging :-)


|> 
|> Ge' Weijers
|> --
|> Ge' Weijers                                    Internet/UUCP: ge@cs.kun.nl
|> Faculty of Mathematics and Computer Science,   (uunet.uu.net!cs.kun.nl!ge)
|> University of Nijmegen, Toernooiveld 1         
|> 6525 ED Nijmegen, the Netherlands              tel. +3180652483 (UTC-2)
|> 

-- 

Jody Hagins             
hagins@gamecock.rtp.dg.com    
Data General Corp.      
62 Alexander Dr.        
RTP, N.C.  27709        
(919) 248-6035