在ubuntu下用nasm和gcc的ld链接程…
来源:互联网 发布:知乎 长沙的知名企业 编辑:程序博客网 时间:2024/05/21 11:01
我们先写一个.asm文件
[SECTION .data]
StrHello db "Hello, kaito!", 0Ah
HelloLen equ $ - StrHello
[SECTION .text]
global _start ;must be decleared for linker(ld)
_start: ;tell linker entry point
mov edx, HelloLen ;message length
mov ecx, StrHello ;message to write
mov ebx, 1 ;file descriptor(stdout, standard output)
mov eax, 4 ;system call number(sys_write)
int 0x80 ;call kernel
mov ebx, 0
mov eax, 1 ;system call number(sys_exit)
int 0x80 ;call kernel
在nasm中可以指定输出文件格式,其中有如下
valid output formats for -f are (`*' denotesdefault):
*bin flat-form binary files (e.g. DOS .COM,.SYS)
ith Intel hex
srec Motorola S-records
aout Linux a.out object files
aoutb NetBSD/FreeBSD a.out objectfiles
coff COFF (i386) object files (e.g. DJGPP forDOS)
elf32 ELF32 (i386) object files (e.g.Linux)
elf64 ELF64 (x86_64) object files (e.g.Linux)
as86 Linux as86 (bin86 version 0.3) objectfiles
obj MS-DOS 16-bit/32-bit OMF objectfiles
win32 Microsoft Win32 (i386) objectfiles
win64 Microsoft Win64 (x86-64) objectfiles
rdf Relocatable Dynamic Object File Formatv2.0
ieee IEEE-695 (LADsoft variant) object fileformat
macho32 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) objectfiles
macho64 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) objectfiles
dbg Trace of all info passed to outputstage
elf ELF (short name for ELF32)
macho MACHO (short name for MACHO32)
win WIN (short name for WIN32)
由于我的虚拟机是i386:x86-64的,所以在编译的时候要选择elf64
nasm -felf64 hello.asm -o hello.o
ld -shello.o -o hello
运行hello文件
./hello
如果想要在64位Linux上编译出32位.o文件,则在编译时加上编译选项 -melf_i386
阅读全文
0 0
- 在ubuntu下用nasm和gcc的ld链接程…
- Ubuntu下用gcc与nasm联合编译
- Ubuntu下用gcc与nasm联合编译
- gcc 和 nasm的区别
- linux 用ld链接nasm编译的elf格式的.o文件报错
- ubuntu 下 gcc 安装和链接
- Ubuntu下ARM开发.ld链接文件的学习笔记
- ubuntu下用Gcc编译器编译c语言的静态和动态链接库范例
- 在linux下用gcc查看代码的【预处理】,【编译】,【汇编】和【链接】
- 使用GCC和NASM在Linux下联合编译
- ubuntu的ld无法链接libcrypto问题解决
- ubuntu的ld无法链接libcrypto问题解决
- Ubuntu下安装nasm
- GCC在Ubuntu Linux下的安装
- GCC/LD编译链接潜规则
- gcc as和ld的学习笔记
- 揪出gcc默认使用的ld链接脚本
- 揪出gcc默认使用的ld链接脚本
- 第9章 虚拟存储器
- 直接给显存发送数据,显示字符串(…
- 再是用数据段的情况下,向显存发送…
- SimpleDateFormat
- 用软盘引导扇区加载.bin文件到内存…
- 在ubuntu下用nasm和gcc的ld链接程…
- 加载setup后,进入保护模式
- Java Language Class Thread
- 关于LDT的使用
- 在保护模式下启动分页机制,并且使…
- ELF Format
- 将博客搬至CSDN
- 过滤器 Filter
- 介绍一款XML格式,轻量级。