Delphi built-in assembler for structure

Hi people there is a way that I can access the pointer to a member of the structure directly from the assembler of strings, I tried this

procedure test(eu:PImageDosHeader);assembler;
asm
    push eu._lfanew
end;

It will not compile, but if I use this

procedure test(eu:Pointer); 
var   
 xx:TImageDosHeader;
 begin    
 xx:=TImageDosHeader(eu^);  
 asm
     push xx._lfanew
 end;
 end;

It works great. Any idea how I can access the structure via a pointer in inline asm? it's a matter of code optimization

+5
source share
3 answers

Another workaround:

procedure test(eu:PImageDosHeader);
asm
    push eu.TImageDosHeader._lfanew
end;
+12
source

The following works:

type
  PMyStruct = ^TMyStruct;
  TMyStruct = record
    A, B: cardinal;
  end;

procedure ShowCard(Card: cardinal);
begin
  ShowMessage(IntToHex(Card, 8));
end;

procedure test(Struct: PMyStruct);
asm
  push ebx                      // We must not alter ebx
  mov ebx, eax                  // eax is Struct; save in ebx
  mov eax, TMyStruct(ebx).A      
  call ShowCard
  mov eax, TMyStruct(ebx).B
  call ShowCard
  pop ebx                        // Restore ebx
end;

procedure TForm6.FormCreate(Sender: TObject);
var
  MyStruct: TMyStruct;
begin
  MyStruct.A := $22222222;
  MyStruct.B := $44444444;
  test(@MyStruct);
end;
+4
source

:

procedure test(const eu: TImageDosHeader);
asm
    push TImageDosHeader([EAX])._lfanew
end;

.

+2

All Articles