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

前端 未结 3 1230
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 12:08

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 ass

相关标签:
3条回答
  • 2021-02-04 12:21

    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).

    0 讨论(0)
  • 2021-02-04 12:26

    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

    0 讨论(0)
  • 2021-02-04 12:36

    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
    
    0 讨论(0)
提交回复
热议问题