您的位置:首页 > 运维架构 > Linux

linux下32位汇编hello, world!

2015-09-23 11:07 585 查看
SECTION .data          ; section containing initialized data
HelMsg: db "Hello World!",10
HelLen: equ $-HelMsg

SECTION .bss           ; section containing uninitialized data

SECTION .text          ; section containing code
global _start      ; linker needs this to find the entry point!

_start:
mov eax,4          ; specify sys_write syscall
mov ebx,1          ; specify file decriptor 1: stdout
mov ecx,HelMsg     ; pass offset of the message
mov edx,HelLen     ; pass the length of the message
int 80H            ; mke syscall to output the text to stdout

mov eax,1          ; sepcify exit syscall
mov ebx,0          ; return zero
int 80H            ; make syscall to terminate the program


在32位主机上编译时编译:

makefile

hello: hello.o
ld -o $@ $^

hello.o: hello.asm
nasm -f elf -g -F stabs $<


在64位的主机上编译时

makefile

hello: hello.o
ld  -m elf_i386 -o $@ $^

hello.o: hello.asm
nasm -f elf32 -g -F stabs $<
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: