Recent

Author Topic: Is there way to access array element in asm ?  (Read 3124 times)

mohsenti

  • Jr. Member
  • **
  • Posts: 58
Is there way to access array element in asm ?
« on: May 01, 2016, 03:19:04 pm »
Hi,
I try to access a element of a byte array in asm like below but can not do that, what is true way ?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   DataTest: array [0..1] of byte;
  4.  begin
  5.   DataTest[0] := 250;
  6.   {$ASMMODE intel}
  7.   asm
  8.            SHL     [DataTest],1
  9.   end;
  10. end;
  11.  

mohsenti

  • Jr. Member
  • **
  • Posts: 58
Re: Is there way to access array element in asm ?
« Reply #1 on: May 01, 2016, 03:29:00 pm »
For more information I test some other codes like below but no one work correct !

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.FormCreate(Sender: TObject);
  3. var
  4.   DataTest: array [0..1] of byte;
  5.   b: PByte;
  6. begin
  7.   DataTest[0] := 250;
  8.   b := @DataTest[0];
  9.   ShowMessage(IntToStr(cardinal(b)));
  10.   {$ASMMODE intel}
  11.   asm
  12.            SHL     BYTE PTR [b],1
  13.   end;
  14.   ShowMessage(IntToStr(cardinal(b)));
  15.   //ShowMessage(IntToStr(DataTest[1]));
  16.   //ShowMessage(IntToStr(DataTest[0]));
  17. end;        
  18.  
  19.  

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   DataTest: array [0..1] of byte;
  4.   b: PByte;
  5. begin
  6.   DataTest[0] := 250;
  7.   b := @DataTest[0];
  8.   ShowMessage(IntToStr(cardinal(b)));
  9.   {$ASMMODE intel}
  10.   asm
  11.            SHL     [b],1
  12.   end;
  13.   ShowMessage(IntToStr(cardinal(b)));
  14.   //ShowMessage(IntToStr(DataTest[1]));
  15.   //ShowMessage(IntToStr(DataTest[0]));
  16. end;        
  17.  

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.FormCreate(Sender: TObject);
  3. var
  4.   DataTest: array [0..1] of byte;
  5.   b: PByte;
  6. begin
  7.   DataTest[0] := 250;
  8.   b := @DataTest[0];
  9.   ShowMessage(IntToStr(cardinal(b)));
  10.   {$ASMMODE intel}
  11.   asm
  12.            SHL     b,1
  13.   end;
  14.   ShowMessage(IntToStr(cardinal(b)));
  15.   //ShowMessage(IntToStr(DataTest[1]));
  16.   //ShowMessage(IntToStr(DataTest[0]));
  17. end;        
  18.  
  19.  

all codes change "b" location (memory address)

Thank you
« Last Edit: May 01, 2016, 03:34:04 pm by mohsenti »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Is there way to access array element in asm ?
« Reply #2 on: May 01, 2016, 03:43:11 pm »
Here (both 3.1.1 and 3.0.0) the original code compiles

mohsenti

  • Jr. Member
  • **
  • Posts: 58
Re: Is there way to access array element in asm ?
« Reply #3 on: May 01, 2016, 05:24:30 pm »
Code: Pascal  [Select][+][-]
  1.  
  2. procedure Add(one,two:PByte);register; assembler;
  3. asm
  4.                 mov rax,one
  5.                 mov rbx,two
  6.                 mov ecx,4
  7.                 clc
  8.                 @loop2:
  9.                         mov dl,byte [rbx]
  10.                         adc byte [rax],dl
  11.                         inc rax
  12.                         inc rbx
  13.                         dec ecx
  14.                         jnz @loop2
  15.                 @carryLoop:
  16.                         adc byte [rax],0
  17.                         inc rax
  18.                         jc @carryLoop
  19. end;
  20.  
  21.  

Above code is my answer!

 

TinyPortal © 2005-2018