1:setup Nasm in linux
1:下载源码包 nasm-x.xx.tar.gz
2: tar -zxf nasm-x.xx.tar.gz
3:cd nasm directory
4:./configure
5:make install
6: nasm --vesion
2:
; hello.asm a first program for nasm for Linux, Intel, gcc
;
; assemble: nasm -f elf hello.asm -o hello.o
; link: gcc -o hello hello.o
; run: hello
; output is: Hello World
SECTION .data ; data section
msg: db "Hello World",10 ; the string to print, 10=cr
len: equ $-msg ; "$" means "here"
; len is a value, not an address
SECTION .text ; code section
global main ; make label available to linker
main: ; standard gcc entry point
mov edx,len ; arg3, length of string to print
mov ecx,msg ; arg2, pointer to string
mov ebx,1 ; arg1, where to write, screen
mov eax,4 ; write command to int 80 hex
int 0x80 ; interrupt 80 hex, call kernel
mov ebx,0 ; exit code, 0=normal
mov eax,1 ; exit command to kernel
int 0x80 ; interrupt 80 hex, call kernel
2:nasm -f elf64 helloworld.asm -o hellowold.o
3:ld hellowold.o -o hello
4:./hello
$nasm -f elf exit.asm
$ld exit.o -o exit
出现下面的结果:
在网上搜了一下解决方案:
之后再执行链接就不会报错了。。。。
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om elf_k1om i386pep i386pe
我之前写的命令行是:ld -o eatsyscall eatsyscall.o
报错后我改了一下: ld -m elf_i386 -o eatsyscall eatsyscall.o
然后就可以了