Field offset lazarus / 62-General ---------------------------------------------------------------------- LemonParty · 2020-05-08 12:18 This code fail on execution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ASMMODE intel}type        TRec = packed record                Data: Pointer;              Count: NativeUInt;                Values: array[0..15]of LongWord;        end;        procedure Unpack16D(const Pack: TRec; var outBuf: LongWord);assembler;nostackframe;asm        mov r8,TRec(Pack).Data        lea r9,TRec(Pack).Values        mov rcx,TRec(Pack).Count        mov eax,[r9+60]end; var        pi16: TRec;        buf: array[0..31]of LongWord;begin        Unpack16D(pi16, buf[0]);        readln;end.When use [rcx+16] instead of TRec(Pack).Values, it works as expected. What is the reason? Compiler v. 3.0.4. ---------------------------------------------------------------------- Thaddy · 2020-05-08 12:28 Which platform are you using? Your record differs in size between platforms. ---------------------------------------------------------------------- LemonParty · 2020-05-08 12:34 Win x64 ---------------------------------------------------------------------- jamie · 2020-05-08 12:46 Maybe because u did not specify byte ptr and thus picked the full size element mov ---------------------------------------------------------------------- ASerge · 2020-05-08 22:08 Quote from: LemonParty on May 08, 2020, 02:18:16 pmWhen use [rcx+16] instead of TRec(Pack).Values, it works as expected. What is the reason? Compiler v. 3.0.4. Not reproduced. FPC 3.0.4 x64. Binary code for Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i lea r9,TRec(Pack).Values and Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i lea r9,[rcx+16] are the same. ---------------------------------------------------------------------- LemonParty · 2020-05-09 08:54 I found the reason. TRec(Pack).Values produce: Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mov     r8, [rcx]lea     r9, [ecx+10h]mov     rcx, [rcx+8]mov     eax, [r9+3Ch]Is this a bug in compiler? ---------------------------------------------------------------------- marcov · 2020-05-09 09:09 That's not the syntax for assembler. I'm surprised this is accepted at all. The correct syntax is afaik Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   lea r9,Pack+TRec.Values which compiles to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         leaq    16(%rcx),%r9 ---------------------------------------------------------------------- LemonParty · 2020-05-09 10:36 Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i lea r9,Pack+TRec.ValuesNot compile in v. 3.0.4. ---------------------------------------------------------------------- LemonParty · 2020-05-09 10:43 Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i lea r9,[Pack+TRec.Values]This work. ---------------------------------------------------------------------- jamie · 2020-05-09 16:12 I think you should rethink your code plan... When I test it here in 64 bit, R8 is LEA of the returning Outbuffer address. but in your code you clobber it why setting R8 from the data, so you have already lost your returning pointer..  Maybe your goal is to set this Data pointer at some point but like I said, you have overwritten the R8 reg so that can no longer happen..   I modified the code abit using R8 as the returning place holder and moves EAX into it.. it works fine this way but  you still have no Data pointer value, but this is at the start of the record anyways.. so no big deal...   Why don't you use the compiler's built in intrinsic to do this ?  it looks like you are reading data past the end of the record which is common in many cases of C coding..  At the end of your record put in a Dummy field that you can cast to what ever...  for example  IAmADummy :Record End; That is one way to do it. from that you can obtain the address of that position..  SomePointer := @MyDummyRecord.IamADummy;  if all you need is offset values of a Record...  then do something like this..  My_UintPtr := @TRec(NIL)^.Values;  Along those lines... ---------------------------------------------------------------------- PascalDragon · 2020-05-09 21:01 Quote from: LemonParty on May 08, 2020, 02:18:16 pmThis code fail on execution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ASMMODE intel}type        TRec = packed record                Data: Pointer;              Count: NativeUInt;                Values: array[0..15]of LongWord;        end;        procedure Unpack16D(const Pack: TRec; var outBuf: LongWord);assembler;nostackframe;asm        mov r8,TRec(Pack).Data        lea r9,TRec(Pack).Values        mov rcx,TRec(Pack).Count        mov eax,[r9+60]end; var        pi16: TRec;        buf: array[0..31]of LongWord;begin        Unpack16D(pi16, buf[0]);        readln;end.When use [rcx+16] instead of TRec(Pack).Values, it works as expected. What is the reason? Compiler v. 3.0.4. Trunk correctly converts TRec(Pack).Values to [rcx + 16]. You might want to test 3.2 RC1 to check whether the fix will be in the release as well. Quote from: marcov on May 09, 2020, 11:09:07 amThat's not the syntax for assembler. I'm surprised this is accepted at all. The correct syntax is afaik Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   lea r9,Pack+TRec.Values which compiles to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         leaq    16(%rcx),%r9 Delphi accepts both, so does FPC.