当前位置: 首页 > news >正文

用nasm汇编器汇编不同位数格式的ELF

在网上找到一个把32位汇编程序转为64位的存储库,
https://codeload.github.com/theadityalunawat/assembler_converter/zip/refs/heads/master
把代码下载下来以后,
32_bit.asm

extern printf
global mainsection .datamessage db "Hello World", 10, 0section .textmain:pushadpush dword messagecall printfadd esp, 4popadret

64_bit.asm

global _startsection .datamessage db "Hello Cloud!",10 , 0section .text
_start:mov rax,1mov rdi,1mov rsi, messagemov rdx, 13syscallmov rax, 60mov rdi, 0syscall

先用fasm程序汇编
结果报各种错误

./fasm asmcov/32_bit.asm
flat assembler  version 1.73.32  (16384 kilobytes memory)
asmcov/32_bit.asm [1]:
extern printf
processed: extern printf
error: illegal instruction../fasm -f elf64 asmcov/64_bit.asm
flat assembler  version 1.73.32
usage: fasm <source> [output]
optional settings:-m <limit>         set the limit in kilobytes for the available memory-p <limit>         set the maximum allowed number of passes-d <name>=<value>  define symbolic variable-s <file>          dump symbolic information for debugging./fasm.x64 asmcov/64_bit.asm
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
asmcov/64_bit.asm [1]:
global _start
processed: global _start
error: illegal instruction.

到nasm主页下载了源代码
编译安装很简单./configure 和 make就行了。

# nasm-2.16.03/nasm asmcov/64_bit.asm
asmcov/64_bit.asm:8: error: instruction not supported in 16-bit mode
asmcov/64_bit.asm:9: error: instruction not supported in 16-bit mode
asmcov/64_bit.asm:10: error: instruction not supported in 16-bit mode
asmcov/64_bit.asm:11: error: instruction not supported in 16-bit mode
asmcov/64_bit.asm:13: error: instruction not supported in 16-bit mode
asmcov/64_bit.asm:14: error: instruction not supported in 16-bit mode

直接汇编出错,加了-f选项就可以汇编出.o文件了,注意它和asm默认保存在同一个目录下,按照assembler_converter源码中README的步骤链接成功,执行结果正确。

# nasm-2.16.03/nasm -f elf64 asmcov/64_bit.asm# nasm-2.16.03/nasm -f elf32 asmcov/32_bit.asm
# ld 64_bit.o -o 64_bit_run
ld: cannot find 64_bit.o: No such file or directory
# ld asmcov/64_bit.o -o 64_bit_run
# ./64_bit_run
Hello Cloud!
# gcc-12 -m32 asmcov/32_bit.o -o 32_bit_run
/usr/bin/ld: warning: asmcov/32_bit.o: missing .note.GNU-stack section implies executable stack
/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/bin/ld: asmcov/32_bit.o: warning: relocation in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
# ./32_bit_run
Hello World

但是用他的翻译器翻译的结果,虽然通过了汇编,但链接警告,执行也卡住,看来是无法工作的。

# g++ asmcov/translator.cpp
# cd asmcov/asmcov# ../a.out
new 64 bit file has been created
/asmcov# cd ..
# nasm-2.16.03/nasm -f elf64 asmcov/64_bit_conv.asm
# ld asmcov/64_bit_conv.o -o 64_bit_conv_run
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
# ./64_bit_conv_run
^C

文章转载自:

http://6o1Nkyy8.dmtLd.cn
http://gw171jXw.dmtLd.cn
http://TJ3YnxI1.dmtLd.cn
http://zDkyCyUX.dmtLd.cn
http://RqP6TQ2s.dmtLd.cn
http://VDosy1Pe.dmtLd.cn
http://7nG4Av0j.dmtLd.cn
http://4wMhodVa.dmtLd.cn
http://upuH4Qjj.dmtLd.cn
http://41noYtTd.dmtLd.cn
http://jHSe2dWn.dmtLd.cn
http://a42QrnoB.dmtLd.cn
http://oqXj40Ua.dmtLd.cn
http://7PztLKJ5.dmtLd.cn
http://rJ4QCJTk.dmtLd.cn
http://s7QidL8d.dmtLd.cn
http://JhEPzR0x.dmtLd.cn
http://pg3q1RZf.dmtLd.cn
http://oXhpyWwb.dmtLd.cn
http://si8LzGf2.dmtLd.cn
http://XTFB5DuS.dmtLd.cn
http://Wp2dqqBh.dmtLd.cn
http://qW1sJCIp.dmtLd.cn
http://EHB2XSjq.dmtLd.cn
http://irrSUwwT.dmtLd.cn
http://blLLVAeX.dmtLd.cn
http://rEzza4mS.dmtLd.cn
http://hZy4SxBh.dmtLd.cn
http://DVSLyKTh.dmtLd.cn
http://sxFeEOA3.dmtLd.cn
http://www.dtcms.com/a/372736.html

相关文章:

  • odoo打印pdf速度慢问题
  • 京东商品评论 API(JSON 数据返回)核心解析
  • SpringMVC(二)
  • 开始理解大型语言模型(LLM)所需的数学基础
  • 搭论文大纲逻辑乱易跑题?AI 3 步梳理框架,自动串逻辑链
  • C#SqlSugar的简单使用
  • 【军事类】军舰识别检测数据集:3400+图像,4类,yolo标注
  • 基于若依框架Vue+TS导出PDF文件的方法
  • ArcGIS学习-18 实战-降雨量空间分布插值分析
  • OpenCV 银行卡号识别
  • CentOS 8重启后网卡不见了解决办法
  • Nginx反向代理和负载均衡详解及使用Nginx和tomcat共同实现动静分离配置
  • UDP的使用
  • WGAI项目图像视频语音识别功能
  • 9.3深度循环神经网络
  • 【嵌入式硬件实例】-555定时器实现自动晚灯(220V)
  • Linux Shell | set、env、export 用法区别
  • 浅聊一下微服务的服务保护
  • Nginx 实战系列(五)—— Nginx流量监控:从stub_status到nginx-module-vts的进阶指南
  • 34. 什么是反射
  • YOLO11 改进、魔改|通道自注意力卷积块CSA-ConvBlock,实现 “轻量化特征增强”
  • 优先搜索(DFS)实战
  • 计算机视觉opencv----银行卡号码识别
  • 第六章、从transformer到nlp大模型:编码器-解码器模型 (Encoder-Decoder)
  • pymodbus启动一个简单的modbus tcp server
  • 【NowCoder】牛客周赛 Round 108 EF (背包问题 | SOSDP)
  • 【ARMday02】
  • OFDR设备开机到出图的5个关键操作步骤
  • ArcGIS学习-19 实战-表面分析
  • 【算法】双指针(二)复写零