64-bit mov

General FreeBASIC programming questions.
Post Reply
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

64-bit mov

Post by deltarho[1859] »

I kmow that this works where ptrBuffer is Any Ptr

Code: Select all

Dim as Ulong TempVar
Asm
  mov eax, Dword Ptr [ptrBuffer]
  mov eax, [eax]
  mov Dword Ptr [TempVar], eax
End Asm
But I cannot do this because the 64-bit mov is differnt to the 32-bit mov.

Code: Select all

Dim as Ulongint TempVar
Asm
  mov rax, Qword Ptr [ptrBuffer]
  mov rax, [rax]
  mov Qword Ptr [TempVar], rax
End Asm
How do I do the 64-bit equivalent to the 32-bit?

I have tried a quite few variations, with successful compilations, but the results are not correct.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: 64-bit mov

Post by srvaldez »

sorry, in my haste I posted wrong code
this example seems work ok

Code: Select all

#ifdef __FB_WIN32__
	#ifdef __FB_64BIT__
		'64-bit
		Dim as Ulongint TempVar
		dim as Ulongint ptr ptrBuffer=allocate(sizeof(Ulongint))
		*ptrBuffer=18446744073709551615ull
		Asm
		  mov rax, Qword Ptr [ptrBuffer]
		  mov rax, [rax]
		  mov Qword Ptr [TempVar], rax
		End Asm
		Print TempVar
		deallocate(ptrBuffer)
	#else
		'32-bit
		Dim as Ulong TempVar
		dim as Ulong ptr ptrBuffer=allocate(sizeof(Ulong))
		*ptrBuffer=4294967295ul
		Asm
		  mov eax, Dword Ptr [ptrBuffer]
		  mov eax, [eax]
		  mov Dword Ptr [TempVar], eax
		End Asm
		Print TempVar
		deallocate(ptrBuffer)
	#endif
#endif
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: 64-bit mov

Post by deltarho[1859] »

Thanks srvaldez.

It is good to know that piece of code was correct. In 64-bit the buffer is filled a little differently, and I was confident that was OK so questioned the posted code. I only made two changes so it looks like something is wrong with the changed buffer fill. In 32-bit mode the buffer is filled using RdRand's 32-bit output and in 64-bit mode the buffer is filled using RdRand's 64-bit output.

Thanks again.
Post Reply