栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在64位Linux和64位处理器上运行32位汇编代码:解释异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在64位Linux和64位处理器上运行32位汇编代码:解释异常

请记住,默认情况下,64位OS上的所有内容都倾向于采用64位。您需要确保(a)在适当的地方使用#include的32位版本(b)与32位库的链接以及(c)构建32位可执行文件。如果您显示makefile的内容(如果有的话)或用于构建此示例的命令,则可能会有所帮助。

FWIW我稍微更改了您的代码(_start-> main):

#include <asm/unistd.h>#include <syscall.h>#define STDOUT 1    .datahellostr:    .ascii "hello wolrdn" ;helloend:    .text    .globl mainmain:    movl $(SYS_write) , %eax  //ssize_t write(int fd, const void *buf, size_t count);    movl $(STDOUT) , %ebx    movl $hellostr , %ecx    movl $(helloend-hellostr) , %edx    int $0x80    movl $(SYS_exit), %eax //void _exit(int status);    xorl %ebx, %ebx    int $0x80    ret

并像这样构建它:

$ gcc -Wall test.S -m32 -o test

确认我们具有32位可执行文件:

$ file testtest: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped

它似乎运行正常:

$ ./testhello wolrd


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/408752.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号