Machine Code..._(re)
Wed, 4 Jun 1997 22:51:11 +0200 (MET DST)
Hi! Just cleaning up a little ...
According to PredatorZeta:
>
> Type
> Byteint = __byte__ Integer;
> Byte = __unsigned__ Byteint;
> Shortint =__short__ Integer;
> Word16 = __unsigned__ Shortint;
`ByteInt', `Byte', and `ShortInt' like above are already built-in in
recent (alpha) versions of GPC. `Word16' also exists but is named
`ShortWord'.
> Function Inportw(port : integer) : word16;
> var temp : word16=0;
> begin
> Asm("inw %%dx, %%ax" : "=a" (temp) : "d" (port));
> Inportw:=temp;
> end;
>
> Function Inportb(port : integer) : byte;
> var temp : byte=0;
> begin
> Asm("inw %%dx, %%al" : "=a" (temp) : "d" (port));
> Inportb:=temp;
> end;
This can be abbreviated further (and indented;-):
Function InPortW ( port: Integer ) result: ShortWord;
begin (* InPortW *)
asm ( 'inw %%dx, %%ax' : '=a' ( result ) : 'd' ( port ) );
end (* InPortW *);
Function InPortB ( port: Integer ) result: Byte;
begin (* InPortB *)
asm ( 'inw %%dx, %%al' : '=a' ( result ) : 'd' ( port ) );
end (* InPortB *);
(NOT TESTED, sorry!)
PredatorZeta, are you sure that it's `inw' in the second case,
not `inb'?
BTW, you can even use these as procedures in your program without loss of
speed: With full optimization `-O3', GPC will automatically inline the
above.
Hope this helps,
Peter
Dr. rer. nat. [970604] Peter Gerwinski, Essen, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
maintainer GNU Pascal [970510] - http://home.pages.de/~gnu-pascal/ [970125]
Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es