Is it possible to run x86 assembly on a x64 operating system?

别来无恙 提交于 2019-12-03 10:27:33

问题


Recently I decided that it was worth getting a try on basic x86 assembly so that it would be easier to debug programs, etc, etc. So I started (about a week ago) learning x86 assembly, in that time, I upgraded my computer to 8GB ram, so obviusly my x86 Windows XP installation was wasting up all that memory, now, I'm running a x64 Windows 7 copy, so the question is:

Is it possible to work with x86 assembly on a x64 operating system? Will it run properly in the emulator? Or should I learn x64 assembly?


回答1:


Yes, of course. Most programs are still 32 bit and run fine on 64-bit Windows systems. Those programs are machine language, which has a one-to-one mapping with assembly (and can be easily disassembled into x86 assembly code).




回答2:


Is it possible to work with x86 assembly on a x64 operating system? Will it run properly in the emulator?

Yes it is possible & it will run properly. Instruction Set Architecture is always backwards compatible.

Registers in x86-64:


(source: usenix.org)

For example: Here you can see that rax is the new 64 General Purpose register but you still can use eax as it refers to lower 32 bits of rax.

Or should I learn x64 assembly?

x86-32 architecture is subset of x86-64. Its like first you learnt x86 then go & find whats new in x86-64 assembly. Once you learn x86 asm. Then this will be a useful resource: http://www.cs.cmu.edu/~fp/courses/15213-s06/misc/asm64-handout.pdf




回答3:


Linux explicitly implements 32 bit support if the compilation option:

CONFIG_IA32_EMULATION=y

is set.

This is done by most sane distros, including Ubuntu 14.04.

32-bit emulation is of course only possible because x86-64 processors are designed to be backwards compatible with 32-bit executables via a 32-bit emulation mode which the kernel knows how to use.

Another thing you have to worry about is the libraries: to compile 32-bit programs, you need 32-bit libraries. On Ubuntu 14.04 AMD64:

sudo apt-get install gcc-multilib

Then we can easily test it out with a hello world:

#include <stdio.h>
#include <stdlib.h>

int main() {
    puts("hello world");
    return EXIT_SUCCESS;
}

and:

gcc -m32 hello_world.c
./a.out

Which prints:

hello world

And:

file a.out

confirms that it is 32 bit:

ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=358f7969deeb2f24a8dd932a0d296887af4eae30, not stripped


来源:https://stackoverflow.com/questions/2125936/is-it-possible-to-run-x86-assembly-on-a-x64-operating-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!