求两小段嵌入式汇编:
1: 两个DWORD相乘,生成另两个DWORD(一个表示进位,一个是尾数),即A*B=C shl 32 + D;
2;三个DWORD相除,(A shl 32 + B) div C = D;
因为DWORD×DWORD>Int64,所以Delphi实现起来有点繁琐。
Delphi调用BCB的Obj为什么失败?
Unsatisfied forward or external declaration 函数名BCB源码H:
#ifndef DWordOpH
#define DWordOpH
//---------------------------------------------------------------------------typedef unsigned long   DWORD;
#endifextern "C" _export int _fastcall  DMul(DWORD A, DWORD B, DWORD& P, DWORD& C);
extern "C" _export int _fastcall  DDiv(DWORD A, DWORD B, DWORD C, DWORD& D);BCB源码CPP:
extern "C" int _fastcall DMul(DWORD A, DWORD B, DWORD& P, DWORD& C)
{
unsigned __int64 S = A * B;
P = S & 0xFFFFFFFF;
C = S>>32;
        return 0;
};extern "C" int _fastcall DDiv(DWORD A, DWORD B, DWORD C, DWORD& D)
{
unsigned __int64 S = A;
S = S<<32 + B;
D = S % C;
        return 0;
};Delphi调用:
{$L DWordOp.obj}
function DMul(A: DWORD; B: DWORD; var P: DWORD; var C: DWORD): integer; external;
function DDiv(A,B,C: DWORD; var D: DWORD): integer; external;开始是Void和Procedure,不行,改为Function也不行。

解决方案 »

  1.   

    给你一段汇编代码Procedure TForm1.Button1Click(Sender:TObject);
    begin
      ASM
         push bx //此行汇编必须要有,且在第一行
         mov ax,0ffh
         add ax,033h
         pop bx            //必须恢复BX寄存器,否则系统出现不可预料的错误,小心当机。
      END;  
    end;
      

  2.   

    hehe,好像就是$FF + $33
      

  3.   

    相乘
    procedure DMUL(A,B: DWORD; var C,S: DWORD);
    asm
      mov eax,A
      mul eax,B
      mov ecx,C
      mov ebx,S
      mov [ebx],eax
      mov [ecx],edx
    end;