Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: convert asm 32 to asm 64 problem


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Nov 11, 2015 11:37 AM Last Post By: Ville Krumlinde
Gerhard Knapp

Posts: 5
Registered: 3/1/04
convert asm 32 to asm 64 problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 7:43 AM
Hello,
This is my problem:
asm
{$IFDEF CPUX86}
mov ecx, core_globals_value
mov edx, dword ptr TSRMLS_DC
mov eax, dword ptr [edx]
mov ecx, dword ptr [eax+ecx*4-4]
mov core_globals, ecx
{$ELSE}
mov rcx, core_globals_value
mov rdx, qword ptr TSRMLS_DC
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*4-4]
mov core_globals, rcx
{$ENDIF}
end;

Delphi 10 Seattle,
TSRMLS_DC is type of Pointer
core_globals_value is a record

Line: mov rax, qword ptr [rdx] causes a vialotion error.

the CPUX86 part works correct, but how i have to alter the x64 part to work?

many thanks if you have a solution
Per Larsen, Nex...

Posts: 28
Registered: 3/19/00
Re: convert asm 32 to asm 64 problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 8:09 AM   in response to: Gerhard Knapp in response to: Gerhard Knapp
Gerhard Knapp wrote:

Hello,
This is my problem:
asm
{$IFDEF CPUX86}
mov ecx, core_globals_value
mov edx, dword ptr TSRMLS_DC
mov eax, dword ptr [edx]
mov ecx, dword ptr [eax+ecx*4-4]
mov core_globals, ecx
{$ELSE}
mov rcx, core_globals_value
mov rdx, qword ptr TSRMLS_DC
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*4-4]
mov core_globals, rcx
{$ENDIF}
end;

Delphi 10 Seattle,
TSRMLS_DC is type of Pointer
core_globals_value is a record

Line: mov rax, qword ptr [rdx] causes a vialotion error.

the CPUX86 part works correct, but how i have to alter the x64 part
to work?

many thanks if you have a solution

The A/V suggests that TSRMLS_DC does not contain a valid (64-bit)
pointer.

Also, this part looks like it might be wrong:

mov rcx, qword ptr [rax+rcx*4-4]

It should probably be

mov rcx, qword ptr [rax+rcx*8-8]

IHTH

Per
Gerhard Knapp

Posts: 5
Registered: 3/1/04
Re: convert asm 32 to asm 64 problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 8:29 AM   in response to: Per Larsen, Nex... in response to: Per Larsen, Nex...
is perhaps here an error?

procedure GetAsmX(TSPointer:pointer);
asm
....
The parameter TSPointer will be filled from a Pointer type, mhm

thanks i correct the next line with *8-8

Per Larsen, NexusDB Larsen wrote:
Gerhard Knapp wrote:

Hello,
This is my problem:
asm
{$IFDEF CPUX86}
mov ecx, core_globals_value
mov edx, dword ptr TSRMLS_DC
mov eax, dword ptr [edx]
mov ecx, dword ptr [eax+ecx*4-4]
mov core_globals, ecx
{$ELSE}
mov rcx, core_globals_value
mov rdx, qword ptr TSRMLS_DC
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*4-4]
mov core_globals, rcx
{$ENDIF}
end;

Delphi 10 Seattle,
TSRMLS_DC is type of Pointer
core_globals_value is a record

Line: mov rax, qword ptr [rdx] causes a vialotion error.

the CPUX86 part works correct, but how i have to alter the x64 part
to work?

many thanks if you have a solution

The A/V suggests that TSRMLS_DC does not contain a valid (64-bit)
pointer.

Also, this part looks like it might be wrong:

mov rcx, qword ptr [rax+rcx*4-4]

It should probably be

mov rcx, qword ptr [rax+rcx*8-8]

IHTH

Per
Gerhard Knapp

Posts: 5
Registered: 3/1/04
Re: convert asm 32 to asm 64 problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 9:18 AM   in response to: Gerhard Knapp in response to: Gerhard Knapp
Dubious, in the debugger delphi said with TSRMLS_DC: no value due of optimation or so
then i wrote it in first line:

mov rdx, qword ptr TSRMLS_DC
mov rcx, core_globals_value
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*8-8]
mov core_globals, rcx

and it seems to work :)
As TSRMLS_DC is in first line, it has a value,
if it is in a seconde line, and core_globals_value before,
it has no value, mhm
no idea why

many thanks
for your answer

Gerhard Knapp wrote:
Hello,
This is my problem:
asm
{$IFDEF CPUX86}
mov ecx, core_globals_value
mov edx, dword ptr TSRMLS_DC
mov eax, dword ptr [edx]
mov ecx, dword ptr [eax+ecx*4-4]
mov core_globals, ecx
{$ELSE}
mov rcx, core_globals_value
mov rdx, qword ptr TSRMLS_DC
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*4-4]
mov core_globals, rcx
{$ENDIF}
end;

Delphi 10 Seattle,
TSRMLS_DC is type of Pointer
core_globals_value is a record

Line: mov rax, qword ptr [rdx] causes a vialotion error.

the CPUX86 part works correct, but how i have to alter the x64 part to work?

many thanks if you have a solution
Ville Krumlinde

Posts: 3
Registered: 4/17/07
Re: convert asm 32 to asm 64 problem  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 11:37 AM   in response to: Gerhard Knapp in response to: Gerhard Knapp
My guess the reason for access violation is this:

I assume TSRMLS_DC is a parameter to the function.

In 32-bit default calling convention, Delphi passes the first two arguments as EAX and EDX.
In 64-bit default calling convention, Delphi passes the first (non-float) two arguments as RCX and RDX.

This means that in your first attempt the first line overwrote RCX, and therefore first argument. So the second line loaded RDX with the wrong value.

When you rearranged the lines you solved this problem.

Gerhard Knapp wrote:
Dubious, in the debugger delphi said with TSRMLS_DC: no value due of optimation or so
then i wrote it in first line:

mov rdx, qword ptr TSRMLS_DC
mov rcx, core_globals_value
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*8-8]
mov core_globals, rcx

and it seems to work :)
As TSRMLS_DC is in first line, it has a value,
if it is in a seconde line, and core_globals_value before,
it has no value, mhm
no idea why

many thanks
for your answer

Gerhard Knapp wrote:
Hello,
This is my problem:
asm
{$IFDEF CPUX86}
mov ecx, core_globals_value
mov edx, dword ptr TSRMLS_DC
mov eax, dword ptr [edx]
mov ecx, dword ptr [eax+ecx*4-4]
mov core_globals, ecx
{$ELSE}
mov rcx, core_globals_value
mov rdx, qword ptr TSRMLS_DC
mov rax, qword ptr [rdx]
mov rcx, qword ptr [rax+rcx*4-4]
mov core_globals, rcx
{$ENDIF}
end;

Delphi 10 Seattle,
TSRMLS_DC is type of Pointer
core_globals_value is a record

Line: mov rax, qword ptr [rdx] causes a vialotion error.

the CPUX86 part works correct, but how i have to alter the x64 part to work?

many thanks if you have a solution
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02