Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine 32/64 bit architecture in assembly

I was reading over this question and wondered if the accepted answer might also be a way to determine the architecture. For instance, in asm could I push a WORD onto the stack and then check SP. Compare the new SP to the old SP:

Diff of 4 means 32 bit
Diff of 8 means 64 bit

Am I correct in this thinking?

like image 583
IAbstract Avatar asked Apr 02 '10 20:04

IAbstract


People also ask

How do you know if I have x86 or x64?

Click Start, type system in the search box, and then click System Information in the Programs list. When System Summary is selected in the navigation pane, the operating system is displayed as follows: For a 64-bit version operating system: X64-based PC appears for the System Type under Item.

How do you find whether your System is 32-bit or 64-bit in Linux?

There is a program called uname installed on Linux that can show us if the Linux system is 32 or 64 bit. If it says x86_64, you are using a 64 bit installation. If it says i368, you are using a 32 bit installation. Uname -i gives you the hardware-platform.

What is the difference between x86 and x64 assembly?

A 32-bit processor on x86 architecture has 32-bit registers, while 64-bit processors have 64-bit registers. Thus, x64 allows the CPU to store more data and access it faster. The register width also determines the amount of memory a computer can utilize. Introduced in 1978.


1 Answers

No, because the size of your stack is based on what mode you are running in (real, protected, long/64, vm86, smm, etc), not on the architecture. If your assembly is running in protected mode for instance, your stack will be 32 bits (or 16 if your operands are 16 bits), even if your processor is x86-64.

Like someone in the comments mentioned, CPUID is the only reliable way to tell what your architecture is.

like image 168
Jeff B Avatar answered Sep 30 '22 16:09

Jeff B