Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$I slackasm/assembler.pas}
- {$X+}
- function MulFunc(): Pointer;
- var
- assembler: TSlackASM;
- begin
- with assembler := TSlackASM.Create() do
- try
- // prologue
- code += _push(ebp);
- code += _mov(esp, ebp);
- // load real args
- code += _mov(ebp+12, edx); // Result pointer
- code += _mov(ebp+08, ebx); // argz (ptr to array [WORD] of Pointer)
- // load lape args
- code += _mov(ref(ebx), eax); // deref ebx into eax
- code += _mov(ref(eax), eax); // mov contents of first arg to eax
- code += _add(imm(4), ebx); // offset by size of pointer
- code += _mov(ref(ebx), ecx); // deref ebx into eax
- code += _mov(ref(ecx), ecx); // mov contents of second arg to ecx
- // implementation
- code += _imul(ecx, eax);
- // result
- code += _mov(eax, ref(edx));
- // epilogue
- code += _pop(ebp);
- code += _ret;
- Result := Finalize();
- finally
- WriteLn(Code);
- Free();
- end;
- end;
- var
- mul: external function(x,y:Int32): Int32;
- begin
- mul := MulFunc();
- WriteLn mul(1000, 5);
- FreeMethod(@mul);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement