Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use 64-bit instruction in a 32-bit application on intel/64-bit win7

Tags:

c++

assembly

My environment is 64-bit win7, VC2010.

Of course, the intel inside is 64-bit CPU.

Can I use the 64-bit instruction/native machine word(64-bit) in a 32-bit application? Since most of my code is 32-bit, I do not want to port it to 64-bit.

For some performance critical hot code, I want to manually optimize it by compiler intrinsic or inline assembly(Also 64-bit VC compiler do NOT support inline assembly), is it possible to run 64-bit code fox example mov rax, rbx in a 32-bit mode application?

like image 306
zhaorufei Avatar asked Sep 28 '13 01:09

zhaorufei


People also ask

Can you run 64-bit applications on a 32-bit operating system?

You cannot (normally) run 64 bit programs on a 32 bit OS.

What happens if you use 64-bit on 32-bit?

Yes, lack of ability to boot or execute any of the 64-bit files. For all intents and purposes, it is essentially impossible to execute a 64-bit instruction on 32-bit hardware, and while 64-bit Windows may have some 32-bit files, the main parts are 64-bit, so it won't even boot.

Will Windows 7 64-bit run 32-bit programs?

In general, you can surely run 32-bit software on a 64 bit PC. All 64 bit systems are compatible with 32-bit programs relying on WOW64, which is the x86 emulator that enables 32-bit Windows-based programs to run seamlessly on 64-bit Windows.

Can you convert a 32-bit program to 64-bit?

If you have a computer with a 32-bit setup, you can upgrade to the 64-bit version without acquiring a new license. The only caveat is that there is no in-place upgrade path to make the switch. The only option is to perform a clean installation of Windows 10.


1 Answers

Actually, you kind of can. The mechanism used to switch from 32 to 64 bit mode (which clearly must exist on a 64 bit OS capable of running 32 bit code) is not in any way protected, and can be used from user code. On Windows it is called Heaven's Gate, and it's pretty simple: just a far call with a segment selector of 33h.

So, how to run 64bit code?

call 33h:your64bitcode
...
your64bitcode:
; do something
retf

There are, of course, some limitations to what you can do from 64bit code entered in that way, because you're not truly in a 64bit process.

like image 101
harold Avatar answered Sep 28 '22 01:09

harold