Advertisement
WarPie90

Untitled

Apr 19th, 2022
1,440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | None | 0 0
  1. {$I slackasm/assembler.pas}
  2. {$X+}
  3.  
  4. function MulFunc(): Pointer;
  5. var
  6.   assembler: TSlackASM;
  7. begin
  8.   with assembler := TSlackASM.Create() do
  9.   try
  10.     // prologue
  11.     code += _push(ebp);
  12.     code += _mov(esp, ebp);
  13.  
  14.     // load real args
  15.     code += _mov(ebp+12, edx);           // Result pointer
  16.     code += _mov(ebp+08, ebx);           // argz (ptr to array [WORD] of Pointer)
  17.  
  18.     // load lape args
  19.     code += _mov(ref(ebx), eax);         // deref ebx into eax
  20.     code += _mov(ref(eax), eax);         // mov contents of first arg to eax
  21.  
  22.     code += _add(imm(4),   ebx);         // offset by size of pointer
  23.     code += _mov(ref(ebx), ecx);         // deref ebx into eax
  24.     code += _mov(ref(ecx), ecx);         // mov contents of second arg to ecx
  25.  
  26.     // implementation
  27.     code += _imul(ecx, eax);
  28.  
  29.     // result
  30.     code += _mov(eax, ref(edx));
  31.  
  32.     // epilogue
  33.     code += _pop(ebp);
  34.     code += _ret;
  35.  
  36.     Result := Finalize();
  37.   finally
  38.     WriteLn(Code);
  39.     Free();
  40.   end;
  41. end;
  42.  
  43. var
  44.   mul: external function(x,y:Int32): Int32;
  45. begin
  46.   mul := MulFunc();
  47.  
  48.   WriteLn mul(1000, 5);
  49.  
  50.   FreeMethod(@mul);
  51. end.
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement