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 $<