I am having a problem to access an element of an array in assembly(delphi).
The code is:
procedure TMaskBit.AllocBuffer;
begin
SetLength(DataIn, 6); //array of integer
DataIn[0] := 1 ;
DataIn[1] := 2 ;
DataIn[2] := 3 ;
DataIn[3] := 4 ;
DataIn[4] :=5 ;
DataIn[5] := 6 ;
end;
procedure TMaskBit.SetValue();
asm
lea edx, [eax].TMaskBit.DataIn //indice
mov ecx, [edx+8] //second ement
mov [EAX].TMaskBit.Z, ecx
end;
What might be wrong?
Thanks!
Dynamic Array is a pointer, so you should use mov
instead of lea
:
type
TIntArray = array of Integer;
TMaskBit = class
Z: Integer;
DataIn: TIntArray;
procedure AllocBuffer;
procedure SetValue();
end;
procedure TMaskBit.AllocBuffer;
begin
SetLength(DataIn, 6); //array of integer
DataIn[0] := 1 ;
DataIn[1] := 2 ;
DataIn[2] := 3 ;
DataIn[3] := 4 ;
DataIn[4] :=5 ;
DataIn[5] := 6 ;
end;
procedure TMaskBit.SetValue();
asm
mov edx, [eax].TMaskBit.DataIn // edx references DataIn[0] !!!
mov ecx, [edx+8] // DataIn[2]
mov [EAX].TMaskBit.Z, ecx
end;
procedure TForm7.Button3Click(Sender: TObject);
var
MB: TMaskBit;
begin
MB:= TMaskBit.Create;
MB.AllocBuffer;
MB.SetValue;
ShowMessage(IntToStr(MB.Z));
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With