AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

ASM in Lazarus

Ein Thema von plusplus · begonnen am 30. Jul 2011 · letzter Beitrag vom 2. Sep 2011
Antwort Antwort
plusplus

Registriert seit: 30. Jul 2010
106 Beiträge
 
Delphi 2009 Architect
 
#1

ASM in Lazarus

  Alt 30. Jul 2011, 09:52
Code:
begin
  AInt := Args[i];
  asm push AInt; end;
end;
the code above works in all versions of delphi, I have set {$asmmode intel} but it seams the push is not working, does anyone have an opinion why that could be.

Cheers

PS: I am working x64 windows version of lazarus 0.9.30
Grid Computing made simple - http://xerocoder.com

Geändert von plusplus (30. Jul 2011 um 09:54 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von implementation
implementation

Registriert seit: 5. Mai 2008
940 Beiträge
 
FreePascal / Lazarus
 
#2

AW: ASM in Lazarus

  Alt 30. Jul 2011, 10:26
What means "is not working"?
  Mit Zitat antworten Zitat
plusplus

Registriert seit: 30. Jul 2010
106 Beiträge
 
Delphi 2009 Architect
 
#3

AW: ASM in Lazarus

  Alt 30. Jul 2011, 10:33
What means "is not working"?
well its not pushing the value. I get always 0. Actually i get a silent access violation when I call push. its really weird. is there an alternative command for push in asm?
Grid Computing made simple - http://xerocoder.com

Geändert von plusplus (30. Jul 2011 um 10:43 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von JamesTKirk
JamesTKirk

Registriert seit: 9. Sep 2004
Ort: München
604 Beiträge
 
FreePascal / Lazarus
 
#4

AW: ASM in Lazarus

  Alt 1. Aug 2011, 08:43
Code:
begin
  AInt := Args[i];
  asm push AInt; end;
end;
the code above works in all versions of delphi, I have set {$asmmode intel} but it seams the push is not working, does anyone have an opinion why that could be.

Cheers

PS: I am working x64 windows version of lazarus 0.9.30
I don't have a x64 version available to test, put try to replace "push" with "pushq".

You might also want to read this regarding the calling convention used on 64-Bit Windows systems (also note the second last paragraph about "push" and "pop").

Regards,
Sven
Sven
[Free Pascal Compiler Entwickler]
this post is printed on 100% recycled electrons
  Mit Zitat antworten Zitat
plusplus

Registriert seit: 30. Jul 2010
106 Beiträge
 
Delphi 2009 Architect
 
#5

AW: ASM in Lazarus

  Alt 1. Sep 2011, 14:05
@JamesTKirk
Thank you man, but pushq is an invalid operand.

Below is actually the code that worked in Delphi, and I am trying to port it to Laz.
Weird thing is, x64 push raises a silent exception and on x86 it crashes the app. I have tried many variations and yet no result.

Please if anyone knows what is wrong, help me. Or if anyone has a diff solution for calling dll's dynamically with dynamic parms, please let me know.

I am trying to make this work on Lazaruz 0.90, for x64 and x86 on Win, Lin, and Mac.

Code:
function DynamicDllCallName(Dll: String; const Name: String; HasResult: Boolean; var Returned: Cardinal; const Parameters: array of Pointer): Boolean;
var
  prc: Pointer;
  x, n: Integer;
  p: Pointer;
  dllh: THandle;
begin
  dllh := GetModuleHandle(PChar(Dll));
  if dllh = 0 then begin
    dllh := LoadLibrary(PChar(Dll));
  end;
  if dllh <> 0 then begin
    prc := GetProcAddress(dllh, PChar(Name));
    if Assigned(prc) then begin
      n := High(Parameters);
      if n > -1 then begin
        x := n;
        repeat
          p := Parameters[x];
          asm
            PUSH p
          end;
          Dec(x);
        until x = -1;
      end;
      asm
        CALL prc
      end;
      if HasResult then begin
        asm
          MOV p, EAX
        end;
        Returned := Cardinal(p);
      end else begin
        Returned := 0;
      end;
    end else begin
      Returned := 0;
    end;
    Result := Assigned(prc);
  end else begin
    Result := false;
  end;
end;
Grid Computing made simple - http://xerocoder.com

Geändert von plusplus ( 1. Sep 2011 um 14:08 Uhr)
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#6

AW: ASM in Lazarus

  Alt 1. Sep 2011, 15:01
You’re calling push right in the middle of your high level code – this is almost bound to cause problems because the asm code generated by the compiler from your source code most likely uses the stack, too. You were just lucky that it didn’t break before.
  Mit Zitat antworten Zitat
Benutzerbild von JamesTKirk
JamesTKirk

Registriert seit: 9. Sep 2004
Ort: München
604 Beiträge
 
FreePascal / Lazarus
 
#7

AW: ASM in Lazarus

  Alt 2. Sep 2011, 08:51
Please if anyone knows what is wrong, help me. Or if anyone has a diff solution for calling dll's dynamically with dynamic parms, please let me know.

I am trying to make this work on Lazaruz 0.90, for x64 and x86 on Win, Lin, and Mac.
In that case I'd personally suggest you to take a look at the library libffi, which stands for Foreign Function Interface and seems to allow what you want to achive. As it's used by other projects like Java Native Access (an alternative to JNI) it should be mature enough and it also supports different processor and OS combinations. The only downside is that it seems that you'll need to manually compile it for Win32 and Win64 using the approbiate MinGW environment (the 32 and the 64 bit one).

Regards,
Sven
Sven
[Free Pascal Compiler Entwickler]
this post is printed on 100% recycled electrons
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz