汇编 Hello World
2014-05-16 21:55
260 查看
section .text global _start ;must be declared for linker (ld) _start: ;tell linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string
执行命令hi
nasm -f elf hello.asm
ld -s -o hello hello.o
在64位的机器上报错,这是因为代码是32架构的,所以链接的时候要指定32位架构
ld: i386 architecture of input file `hello.o' is incompatible with i386:x86-64 output
解决方法指定32位架构
ld -m elf_i386 -s -o hello hello.o 调试 nasm -f elf hello.asm -g -F stabs -f 指定输出文件格式, -g 激活调试 -F 调试信息格式 gdb 都是stabs
gdb hello
出错
没有符号表被读取。请使用 "file" 命令。
还是有问题
unfortunately, nasm '-g' switch does not generate proper debug info for gdb; this is nasm bug, I think
nasm 加上-g 似乎是出不了调试信息的
换成下面这样的命令
nasm -f elf -g hello.asm
似乎是没有加上-g 命令的原因
需要执行 gcc -g -o hello hello.o -m32
但是 x64的gcc不行,不能搞定32
只好sudo apt-get install libc6-dev-i386 了。
网上搜到的,最后好用了。
相关文章推荐
- 学第一个汇编程序hello world的说明笔记
- 8086汇编1:HELLO WORLD
- 汇编教程8:hello world
- 汇编语言的Hello World
- 汇编语言的Hello World
- 最"小"的程序--内嵌汇编实现的hello world
- 汇编 Hello World
- 汇编一日一学(1)--Hello World!
- 汇编实验之hello world是怎么工作的
- 汇编Hello World
- 第一个汇编程序学习"Hello world!"
- Hello World! 不容易——汇编 Hello Wold
- 【原译】汇编编程之:Hello World!详解
- “Hello World”—— 第一个汇编程序
- Windows汇编带颜色显示Hello World
- 汇编语言hello world 代码实现
- 汇编的“Hello World!”
- 汇编hello world
- 汇编程序hello world
- 「C语言」「汇编」C输出hello world!系统发生了什么?