Machine Code..._(re)

Fri, 2 May 1997 17:20:32 +0200



According to Peter:

>     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'?

Thanks Peter for your bugfixes to my procedures! I know, I'm very
absent-minded in
these days..."inw" it's because I cute and paste in Rhide the first
proc!!! BTW, here it's occasion to explain two things (heheheh):

1)_The reserved word "result" ISN'T explained properly in the info
documentation. (at least in
my version!!???). It work, but with this stupid warning:

Warning:  return value of function not assigned

I think because GPC can't consider the Asm assignment as a real
assignment....

2)_The code outputted from your proc with -O2 switch activated is:

1	pushl %ebp
2	movl %esp,%ebp
3	subl $12,%esp
4	movl %ecx,-4(%ebp)
5	movl 8(%ebp),%edx
/APP
6	inb %dx, %al
/NOAPP
7	movb %al,-5(%ebp)                            
8	movb -5(%ebp),%al                            |
9	leave
10	ret

=8-||||| AAAAAAAARRRRGGGHHH!!!8-)) Whatta  the lines 7 and 8 do??????
NOTHING!!!
If I cutout these lines the code works IDeNtIcAL!! Also this cost >3<
clock cycles on Pentium, for the AGI stall...

> PredatorZeta, are you sure that it's `inw' in the second case,
> not `inb'?

Uhhmmmm....OKK, This is my fault:))))))))))))

> 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.

Trust me, with these macro:
{$DEFINE Inportw(port,myvar) Asm("inw %%dx, %%ax" : "=a" (myvar) : "d"
(port))}
{$DEFINE Inportb(port,myvar) Asm("inb %%dx, %%al" : "=a" (myvar) : "d"
(port))}

the code works without useless MOVs, and it's inlined with or without
-O3.8-))))))

Cya...

-- 
[<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<]
|  Codename: PrEdAtOr~Z;   Sex: Male;     Status: Free coder |
*              E-mail: predatorzeta@geocities.com                      *
|    URL: http://www.geocities.com/SiliconValley/Vista/6573      |
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]


PredatorZeta (predatorzeta@geocities.com)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es