masm和delphi混编的高手请过来看看
我自己实验了n种调用方式,有些编译通不过,有些是AV错误
// masm 源码
.486
.model flat, stdcall
option casemap: none
include windows.inc
.code
Fun1 proc Int1: DWORD, Int2: DWORD
mov eax, Int1
add eax, Int2
ret
Fun1 endp
// delphi中调用
...
{$L myasm.obj}
...
function Fun1(Int1, Int2: integer): integer; external; stdcal;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := IntToStr(Fun1(3, 4));
end;
[解决办法]
我查了一下国外的资料,看到:
Unfortunately, Delphi doesn 't like OBJ files that MASM produces. For all but the most trivial of assembly modules, Delphi will reject the MASM 's output. Borland Delphi expects external assembly modules to be written with Borland 's assembler, TASM32.EXE (the 32-bit Turbo Assembler).
看样子,delphi不能直接调用masm编译的obj文件。
[解决办法]
用tasm编译阿,nasm也可以,masm就不行,不过应该编译的时候就提示你obj格式不对才对阿
[解决办法]
可能少了.public
在delphi里可以直接嵌入汇编,比如:
var
i:integer;
begin
……
asm
mov eax,i
and eax,15
mov i,eax
end;
end;
[解决办法]
手工做一些工作也是可以的。
首先ml 要使用/Zm选项生成兼容obj;
其次,Delphi找不到符号诸如fun1的问题是masm生成的obj中是类似_fun1@8这种名字,要使用ultraedit之类的工具把obj中名字修改一下,比如把@替换为_,然后在Delphi中声明_fun1_8的external过程就可以了。
所以说意义不大,用tasm、nasm就好了,何必那么麻烦。