64-bit op codes in 32-bit OS
64-bit op codes in 32-bit OS
If you are using the 32-bit FB compiler running under 32-bit Windows 10 on an x64 processor, can you use 64-bit op codes in ASM?
Does the processor run in "32-bit mode", or is it OS agnostic? I mean, does the OS switch the processor from "64-bit mode" to "32-bit mode", assuming there is such a thing?
Does the processor run in "32-bit mode", or is it OS agnostic? I mean, does the OS switch the processor from "64-bit mode" to "32-bit mode", assuming there is such a thing?
Re: 64-bit op codes in 32-bit OS
Hello,If you are using the 32-bit FB compiler running under 32-bit Windows 10 on an x64 processor, can you use 64-bit op codes in ASM?
You cannot run 64-bit applications on a 32-bit Windows 10\8\7.
Re: 64-bit op codes in 32-bit OS
You can't as far I know.
For example the 32bit assembler doesn't know 64bit registers (rax, etc).
Post a short piece of code showing what you want to do.
A 32bit executable started on 64bit OS is recognized as 32bit and is running inside a sort of 'emulator' for all the system calls.
What is your goal ?
Anyway my advice is : Keep things simple.
If running only on 32bit compile to 32bit.
If running only on 64bit compile to 64bit.
If running on 32bit and 64bit compile to 32bit.
For example the 32bit assembler doesn't know 64bit registers (rax, etc).
Post a short piece of code showing what you want to do.
A 32bit executable started on 64bit OS is recognized as 32bit and is running inside a sort of 'emulator' for all the system calls.
What is your goal ?
Anyway my advice is : Keep things simple.
If running only on 32bit compile to 32bit.
If running only on 64bit compile to 64bit.
If running on 32bit and 64bit compile to 32bit.
Re: 64-bit op codes in 32-bit OS
I'm trying to reverse the endianness of a 64-bit qword.
This is 32-bit code:
I was hoping I could use this:
This is 32-bit code:
Code: Select all
Function EndianRev64( ByVal num As ULongInt ) As ULongInt
ASM
mov eax, [num]
mov edx, [num + 4]
bswap eax
bswap edx
mov [Function + 4], eax
mov [Function], edx
End ASM
' Return num
End Function
Print Hex( EndianRev64(&H1122334455667788) )
sleep
Code: Select all
Function EndianRev64( ByVal num As ULongInt ) As ULongInt
ASM
mov rax, [num]
bswap rax
mov [Function], rax
End ASM
End Function
Re: 64-bit op codes in 32-bit OS
pshufb ? https://www.felixcloutier.com/x86/pshufb.html
Requires some alignment here and there though.
Requires some alignment here and there though.
Re: 64-bit op codes in 32-bit OS
I understand that x86 processors have real and protected modes. I'm asking if they also have 32-bit and 64-bit modes. If the answer is yes, then would a processor running in 32-bit mode raise an exception if it were to encounter a 64-bit op code?
Does the compiler have a directive which would enable me to say, "yes, I know you're a 32-bit compiler, and I know that the OS is 32-bit, but I have a 64-bit processor and I would really like to use a 64-bit op code"?
Alternatively, just as a thought experiment that would help me to understand the inner workings, what if I were to compile a 32-bit EXE including a 32-bit ASM, and then hack the binary ASM routine to replace 32-bit op codes with 64-bit RAX op codes? Windows would still see a 32-bit EXE, but will the code execute without error?
Does the compiler have a directive which would enable me to say, "yes, I know you're a 32-bit compiler, and I know that the OS is 32-bit, but I have a 64-bit processor and I would really like to use a 64-bit op code"?
Alternatively, just as a thought experiment that would help me to understand the inner workings, what if I were to compile a 32-bit EXE including a 32-bit ASM, and then hack the binary ASM routine to replace 32-bit op codes with 64-bit RAX op codes? Windows would still see a 32-bit EXE, but will the code execute without error?
Re: 64-bit op codes in 32-bit OS
Not just that. The same instruction might be interpreted differently, namely using the default register size for that mode. So the opcode is not necessarily different.
Just get both a 32-bit and 64-bit compiler and familiarize yourself with "objdump" to see generated assembler annotated with the byte sequences.Alternatively, just as a thought experiment that would help me to understand the inner workings, what if I were to compile a 32-bit EXE including a 32-bit ASM, and then hack the binary ASM routine to replace 32-bit op codes with 64-bit RAX op codes? Windows would still see a 32-bit EXE, but will the code execute without error?
Re: 64-bit op codes in 32-bit OS
Unless you need to call the function million of times the difference of execution time is not visible.
You can use __FB_64BIT__ to get an executable according the OS of destination, obviously when compiling not when running.
#ifdef __FB_64BIT__
'...instructions for 64bit OSes...
#else
'...instructions for other OSes
#endif
You can use __FB_64BIT__ to get an executable according the OS of destination, obviously when compiling not when running.
#ifdef __FB_64BIT__
'...instructions for 64bit OSes...
#else
'...instructions for other OSes
#endif
Re: 64-bit op codes in 32-bit OS
I have to test whether the data pattern in each sector of a 1TB drive is equal to its big-endian LBA. The program will be I/O bound, so maybe the percentage difference in execution time won't be significant.
Re: 64-bit op codes in 32-bit OS
I tried this code but it crashes with no output. I have a Core 2 Duo, so I guess it's too old.
Edit:
Could it be an alignment problem? If so, how do I deal with it?
I tried "mov mm0" op codes, but the compiler rejected them.
Code: Select all
Function BytSwap8( Byval qword As uLongInt ) As uLongInt
Dim Swap8Mask As Const uLongInt = &H0607040502030001
ASM
movups xmm1, [Swap8Mask]
movups xmm0, [qword]
pshufb xmm0, xmm1 ' Swap8Mask
movups [Function], xmm0
End ASM
End Function
Print Hex( BytSwap8(&H1122334455667788) )
Sleep
Could it be an alignment problem? If so, how do I deal with it?
I tried "mov mm0" op codes, but the compiler rejected them.
Re: 64-bit op codes in 32-bit OS
xmm# are 128 bit ( oword ) and you are trying to use them as 64-bit, perhaps if you use an array you could make it work
it's not an alignment problem because movups deals with unaligned memory
it's not an alignment problem because movups deals with unaligned memory
Re: 64-bit op codes in 32-bit OS
This compiles without error but still hangs during execution.
Code: Select all
Function BytSwap8( Byval qword As uLongInt ) As uLongInt
Dim Swap8Mask As Const uLongInt = &H0607040502030001
ASM
movq mm1, [Swap8Mask]
movq mm0, [qword]
pshufb mm0, mm1 ' Swap8Mask
movq [Function], mm0
End ASM
End Function
Print Hex( BytSwap8(&H1122334455667788) )
sleep
Re: 64-bit op codes in 32-bit OS
My code now executes properly, after copying the "qword" argument into a new variable, "qword2". I don't understand why this should be so.
Code: Select all
Function EndianRev64( Byval qword As uLongInt ) As uLongInt
Dim Swap8Mask As Const uLongInt = &H0001020304050607
Dim qword2 As uLongInt
qword2 = qword
ASM
movq mm1, [Swap8Mask]
movq mm0, [qword2] ' <- this op code causes hanging on execution
pshufb mm0, mm1 ' Swap8Mask
movq [Function], mm0
End ASM
End Function
Print Hex( EndianRev64(&H1122334455667788) )
Sleep
Re: 64-bit op codes in 32-bit OS
This compiles OK, but hangs on execution. I'm stumped.
Code: Select all
Dim Swap8Mask As Const uLongInt = &H0001020304050607
Dim qword As uLongInt
Dim qwresult As uLongInt
qword = &H8877665544332211
ASM
movq mm1, [Swap8Mask]
movq mm0, [qword] ' <- this op code causes hanging on execution
pshufb mm0, mm1 ' Swap8Mask
movq [qwresult], mm0
End ASM
Print Hex( qwresult )
Sleep
Re: 64-bit op codes in 32-bit OS
This works:
It appears that "qword" is an illegal variable name, probably because it is reserved.
Doh!
Code: Select all
Dim Swap8Mask As Const uLongInt = &H0001020304050607
Dim qword1 As uLongInt
Dim qwresult As uLongInt
qword1 = &H8877665544332211
ASM
movq mm1, [Swap8Mask]
movq mm0, [qword1] ' <- this line causes hanging on execution if variable name is "qword"
pshufb mm0, mm1 ' Swap8Mask
movq [qwresult], mm0
End ASM
Print Hex( qwresult )
Sleep
Doh!