linux将汇编转为机器码,如何将汇编语言转化为机器码 |
您所在的位置:网站首页 › 如何将汇编语言转为机器语言 › linux将汇编转为机器码,如何将汇编语言转化为机器码 |
很简单,使用gcc即可,我们写如下程序: pop eax 复制代码 保存为文本文件,命名为test.s 然后使用gcc在32位的环境下编译 gcc test.s 复制代码 结果会报错,为什么呢? /usr/bin/ld: /tmp/ccj87S8M.o: relocation R_X86_64_32S against undefined >symbol eax' can not be used when making a PIE object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function_start': (.text+0x20): undefined reference to `main' /usr/bin/ld: final link failed: Invalid operation collect2: error: ld returned 1 exit status 因为gcc默认汇编是要编译链接一气呵成的。这里我们使用参数-c,即可只编译不链接。 gcc -c test.s 复制代码 这样就出来了一个test.o文件,里面只有pop eax的机器码,我们可以使用objdump -d查看。 objdump -d test.o 复制代码 可以看到pop eax被转化为了popq,为什么呢?因为gcc采用的是AT&T 语法pop eax要写成pop %eax再编译才行 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |