发新话题
打印

Delphi嵌入式汇编一例

Delphi嵌入式汇编一例

用delphi写的程序,把x指针指向的4个字节次序颠倒过来:
复制内容到剪贴板
代码:
function toulong(x: pchar): longword;
begin
   result := (longword(x^) shl 24) or
     (longword((x + 1)^) shl 16) or
     (longword((x + 2)^) shl 8) or
     (longword((x + 3)^));
end;
以下是用delphi的嵌入式汇编写法:
复制内容到剪贴板
代码:
function toulong(x: pchar): longword;
asm
   mov esi,eax
   mov ax,[esi]
   xchg ah,al
   shl eax,16
   mov ax,[esi+2]
   xchg ah,al
end;
说明:默认情况下,delphi使用“register”方式,若参数在3个已内,
将分别使用eax、edx和ecx,超过3个参数部分将使用堆栈。返回参数的
存放视长度而定,例如8位用al返回,16位用ax,32位用eax,64位用用两个
32位寄存器edx:eax,其中eax是低位。

TOP

发新话题