Board index » delphi » Pascal Assember <<>> Delphi Assembler

Pascal Assember <<>> Delphi Assembler

Hello,

I've a big problem. I have a assembler function. But these is for
Pascal, and not for Delphi (2.0):

function SwapLong(l: longint): longint; near; assembler;
  asm
    MOV DH,[BP+4];
    MOV DL,[BP+5];
    MOV AH,[BP+6];
    MOV AL,[BP+7];
  end;

The function works under TurboPascal (6.0), but not under Delphi. Can
somebody "translate" it in Delphi or tell me, what this routine do ?
Thanks in advance.

Ralf Ebert
eb...@kamenz.de
Sorry my bad English.

 

Re:Pascal Assember <<>> Delphi Assembler


Hi

Quote
On Sun, 11 May 1997 12:08:52 GMT, eb...@kamenz.de (Ralf Ebert) wrote:
>I've a big problem. I have a assembler function. But these is for
>Pascal, and not for Delphi (2.0):

>function SwapLong(l: longint): longint; near; assembler;
>  asm
>    MOV DH,[BP+4];
>    MOV DL,[BP+5];
>    MOV AH,[BP+6];
>    MOV AL,[BP+7];
>  end;

For PC >= i486:

function SwapLong(l: longint): longint; assembler;
  asm
    bswap eax
  end;

Regards,
Victor Ishikeev

Re:Pascal Assember <<>> Delphi Assembler


Quote
Ralf Ebert wrote:
> I've a big problem. I have a assembler function. But these is for
> Pascal, and not for Delphi (2.0):

> function SwapLong(l: longint): longint; near; assembler;
>   asm
>     MOV DH,[BP+4];
>     MOV DL,[BP+5];
>     MOV AH,[BP+6];
>     MOV AL,[BP+7];
>   end;

> The function works under TurboPascal (6.0), but not under Delphi. Can
> somebody "translate" it in Delphi or tell me, what this routine do ?

It seems to swap the two Word values of which 'l' consists. Or (less
probable, but I could not test it) it might reverse the 4 bytes in 'l'.

The first functionality can be implemented as follows (tested with D1):

function SwapLong(l: longint): longint;
begin
   Result := l shl 16 + l shr 16
end;

Bye,
Peter

Re:Pascal Assember <<>> Delphi Assembler


Quote
> > I've a big problem. I have a assembler function. But these is for
> > Pascal, and not for Delphi (2.0):

> > function SwapLong(l: longint): longint; near; assembler;
> >   asm
> >     MOV DH,[BP+4];
> >     MOV DL,[BP+5];
> >     MOV AH,[BP+6];
> >     MOV AL,[BP+7];
> >   end;

> > The function works under TurboPascal (6.0), but not under Delphi. Can
> > somebody "translate" it in Delphi or tell me, what this routine do ?
> It seems to swap the two Word values of which 'l' consists. Or (less
> probable, but I could not test it) it might reverse the 4 bytes in 'l'.

> The first functionality can be implemented as follows (tested with D1):

> function SwapLong(l: longint): longint;
> begin
>    Result := l shl 16 + l shr 16
> end;

It seems much more changing between big endian and small endian ("turning"
all bytes) like it is needed to load values generated by other processors
like MC680x0. Use one of the following assembler routine (depends if you
app needs to run on 386 machines):

//Delphi 32 Bit, 486 or better
function SwapLong(L: Integer): Integer; Register; Assembler;
asm
  bswap eax
end;

//Delphi 32 Bit, 386 compatibility
function SwapLong(L: Integer): Integer; Register; Assembler;
asm
  xchg al,ah
  ror eax,16
  xchg al,ah
end;

Arsne von Wyss
avonw...@datacomm.ch

Re:Pascal Assember <<>> Delphi Assembler


Quote
> //Delphi 32 Bit, 386 compatibility
> function SwapLong(L: Integer): Integer; Register; Assembler;
> asm
>   xchg al,ah
>   ror eax,16
>   xchg al,ah
> end;

asm
  ror ax,8
  ror eax,16
  ror ax,8
end;

That's faster ;-)

Marcel Kilgus

Re:Pascal Assember <<>> Delphi Assembler


Quote
Ralf Ebert (eb...@kamenz.de) wrote:

: Hello,

: I've a big problem. I have a assembler function. But these is for
: Pascal, and not for Delphi (2.0):

: function SwapLong(l: longint): longint; near; assembler;
:   asm
:     MOV DH,[BP+4];
:     MOV DL,[BP+5];
:     MOV AH,[BP+6];
:     MOV AL,[BP+7];
:   end;

I'd suggest

 function SwapLong(l: longint): longint; near;
 register;
 assembler;
   asm
     ror eax,16
   end;  

--
Zhenya Sorokin

E-mail     : soro...@ps1.iaee.tuwien.ac.at, s...@rs6.iaee.tuwien.ac.at
Paper-mail : E. Sorokin, Gusshausstr. 27/359-4, 1040 Vienna, Austria
Voice-mail : +43(1)58801-3703, -3948
Fax-mail   : +43(1)504 2477

Other Threads