64位linux下玩32位汇编编程
利用下假期,打算把linux下的汇编语言给熟悉下,结果是以32位为版本的,只能在办公室的机器上跑了个opensuse的32位版本,家里的suse挂了,无法输入中文。打算再安装下32位系统,今天找到了个解决方法,记录如下:
代码如下,文件名位test32.s:
.section .data .section .text .globl _start
_start:
pushl $
pushl $
call sumer
addl $, %esp
movl %eax, %ebx
movl $, %eax
int $0x80 .type sumer, @function sumer:
pushl %ebp
movl %esp, %ebp
movl (%ebp), %eax
movl (%ebp), %ecx
addl %ecx, %eax
popl %ebp
ret
无法按照原来的方式,直接用as test32.s -o test32.o汇编
直接用ld test32.o -o test32链接
直接报错,由于我的linux是64位,解决方法就是在两个命令选项中加上适当的选项即可。
正确的命令是这样的,直接用as test32.s -o test32.o --32 汇编
直接用ld -m elf_i386 test32.o -o test32链接
其中:-m参数是让ld模仿后面跟的连接器,也就是elf_i386格式的连接器,
--32参数是使用32位个是的汇编进行代码汇编,
如果有以下代码test321.c
#include <stdio.h>
int factorial(int num){
if( == num){
return ;
}
return num * factorial(num - );
}
int main(int argc, char **argv)
{
printf("factorial(5): %d\n", factorial());
return ;
}
在64位系统中,直接使用gcc test321.c -S test321.s,64位汇编代码如下
.file "test321.c"
.text
.globl factorial
.type factorial, @function
factorial:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset
.cfi_offset , -
movq %rsp, %rbp
.cfi_def_cfa_register
subq $, %rsp
movl %edi, -(%rbp)
cmpl $, -(%rbp)
jne .L2
movl $, %eax
jmp .L3
.L2:
movl -(%rbp), %eax
subl $, %eax
movl %eax, %edi
call factorial
imull -(%rbp), %eax
.L3:
leave
.cfi_def_cfa ,
ret
.cfi_endproc
.LFE0:
.size factorial, .-factorial
.section .rodata
.LC0:
.string "factorial(5): %d\n"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset
.cfi_offset , -
movq %rsp, %rbp
.cfi_def_cfa_register
subq $, %rsp
movl %edi, -(%rbp)
movq %rsi, -(%rbp)
movl $, %edi
call factorial
movl %eax, %esi
leaq .LC0(%rip), %rdi
movl $, %eax
call printf@PLT
movl $, %eax
leave
.cfi_def_cfa ,
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (GNU) 9.1.0"
.section .note.GNU-stack,"",@progbits
~
在64位系统中,使用gcc test321.c -S -m32 test321.s,32位汇编代码如下
.file "test321.c"
.text
.globl factorial
.type factorial, @function
factorial:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset
.cfi_offset , -
movl %esp, %ebp
.cfi_def_cfa_register
subl $, %esp
call __x86.get_pc_thunk.ax
addl $_GLOBAL_OFFSET_TABLE_, %eax
cmpl $, (%ebp)
jne .L2
movl $, %eax
jmp .L3
.L2:
movl (%ebp), %eax
subl $, %eax
subl $, %esp
pushl %eax
call factorial
addl $, %esp
imull (%ebp), %eax
.L3:
leave
.cfi_restore
.cfi_def_cfa ,
ret
.cfi_endproc
.LFE0:
.size factorial, .-factorial
.section .rodata
.LC0:
.string "factorial(5): %d\n"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
leal (%esp), %ecx
.cfi_def_cfa ,
andl $-, %esp
pushl -(%ecx)
pushl %ebp
.cfi_escape 0x10,0x5,0x2,0x75,
movl %esp, %ebp
pushl %ebx
pushl %ecx
.cfi_escape 0xf,0x3,0x75,0x78,0x6
.cfi_escape 0x10,0x3,0x2,0x75,0x7c
call __x86.get_pc_thunk.bx
addl $_GLOBAL_OFFSET_TABLE_, %ebx
subl $, %esp
pushl $
call factorial
addl $, %esp
subl $, %esp
pushl %eax
leal .LC0@GOTOFF(%ebx), %eax
pushl %eax
call printf@PLT
addl $, %esp
movl $, %eax
leal -(%ebp), %esp
popl %ecx
.cfi_restore
.cfi_def_cfa ,
popl %ebx
.cfi_restore
popl %ebp
.cfi_restore
leal -(%ecx), %esp
.cfi_def_cfa ,
ret
.cfi_endproc
.LFE1:
.size main, .-main
.section .text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
.globl __x86.get_pc_thunk.ax
.hidden __x86.get_pc_thunk.ax
.type __x86.get_pc_thunk.ax, @function
__x86.get_pc_thunk.ax:
.LFB2:
.cfi_startproc
movl (%esp), %eax
ret
.cfi_endproc
.LFE2:
.section .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
.globl __x86.get_pc_thunk.bx
.hidden __x86.get_pc_thunk.bx
.type __x86.get_pc_thunk.bx, @function
__x86.get_pc_thunk.bx:
.LFB3:
.cfi_startproc
movl (%esp), %ebx
ret
.cfi_endproc
.LFE3:
.ident "GCC: (GNU) 9.1.0"
.section .note.GNU-stack,"",@progbits
linux下命令的选项比命令更重要
64位linux下玩32位汇编编程的更多相关文章
- 在64位linux下编译32位程序
在64位linux下编译32位程序 http://blog.csdn.net/xsckernel/article/details/38045783
- 64位系统下注册32位dll文件
64位系统下注册32位dll文件 在64位系统里注册32位软件所需的一些dll会提示不兼容,大概因为32 位进程不能加载64位Dll,64位进程也不可以加载32的导致. 若要支持的32 位和64 位C ...
- 64位系统下注册32位dll、ax文件
64位系统下注册32位dll.ax文件. 换了64位系统遇到的新问题,目前常用的影音处理软件多数为32位. 注册这些32的滤镜会提示不兼容,大概因为32 位进程不能加载64位Dll,64位进程也不可以 ...
- <摘录>如何在64位linux强制编译32位应用程序
GDC注:因为需要解决在linux64机上编译32位的mongodb(没办法,因为编译的php是32位,然后我想将mongdb扩展添加到php中),在网上搜了很多文章,感觉这篇好懂,而且好用.我使用的 ...
- 64位操作系统下调用32位com的问题
Hello Guys! I am trying to create a simple VBS script to automatically open some .tif images from a ...
- WinDbg 在64位系统下转储32位进程
在64位系统下,首先要判断进程是32位,还是64位 在Win8之前,进程名后带星号(*)则是32位进程.但Win8.1后,则不显示星号.需要选出“平台”列,来确认32位,还是64位. 在64位系统下的 ...
- pyinstaller在64位系统下打包32位程序
使用环境说明:win10 64位,已安装python3.6-64位版本 遇到的问题:win10 64位打包成exe文件后,不能在32位系统运行 需求:使用python打包生成exe文件,win64位和 ...
- 在64位linux上编译32位程序 for i386 intel
编辑中 # ld -V GNU ld version 2.15.92.0.2 20040927 Supported emulations: elf_x86_64 elf_i386 i386linux ...
- 在64位Linux上安装32位gmp大数库
前期准备: 如果没有安装32位gcc和g++环境的话,可能会导致安装失败,此时请参考上一篇博文 http://www.cnblogs.com/weir007/p/5977759.html,根据系统版本 ...
随机推荐
- Xamarin开发综述
https://blog.csdn.net/qq_41647999/article/details/84844357 一. 前言这十来天对Xamarin的学习踩了很多的坑,说来也是一把心酸泪,下面为大 ...
- 【原创】大叔经验分享(88)jenkins假死
jenkins安装启动后,使用systemctl来进行进程监控 # systemctl enable jenkins 但是还是经常发生jenkins进程挂了,不会自动重启,通过systemctl查看状 ...
- Linux查看系统及版本信息
1.查看操作系统版本cat /proc/version 2.查看系统发行版cat /etc/issue 或cat /etc/redhat-release 3.查看系统内核信息uname -a
- 私服nexus的权限问题,带admin和带view的区别
admin和view的区别只找到了这个解释: https://blog.csdn.net/tian_111222333/article/details/100159983 最终得出答案,我只需要给他们 ...
- 使用ctypes调用系统C API函数需要注意的问题,函数参数中有指针或结构体的情况下最好不要修改argtypes
有人向我反应,在代码里同时用我的python模块uiautomation和其它另一个模块后,脚本运行时会报错,但单独使用任意一个模块时都是正常的,没有错误.issue链接 我用一个例子来演示下这个问题 ...
- 二〇一八-美团工程师面试解析(Java)
一轮面试: 小数是怎么存的 算法题:N二进制有多少个1 Linux命令(不熟悉 JVM垃圾回收算法 C或者伪代码实现复制算法 volatile 树的先序中序后序以及应用场景 Mysql存储记录的数据结 ...
- Netty UDP 使用采坑
使用Netty搭建UDP服务收集日志,使用过程中发现,部分日志接收不到,排查发现,都是大日志记录不到,后查询相关文档进行如下修改 EventLoopGroup workerGroup = new Ni ...
- PyQt5多个GUI界面设计
版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90454379 - 写在前面 本科毕业设计终于告一段落了.特 ...
- How to resolve emulator cannot be launched issue by command line
Issue: Resolution: 1. Open the system variables, find the Path and edit it, add below item : C:\User ...
- My97DatePicker(js日期插件) v4.8
1.下载地址 https://files.cnblogs.com/files/yu-shang/My97DatePicker.zip 2.文档地址 http://my97.net/demo/index ...