Linux compilation environment

Linux assembler syntax

Assembly language programming under DOS / Windows, these are the Intel style assembly code. But in the Unix and Linux systems, greater use of format or AT & T, the two have very different styles for Intel, we configure our environment on syntax

Installation NASM

$ sudo apt-get install nasm

New hello.asm file

; Hello.asm
sectionTop .data; data segment declaration
msg db "Hello, world!" , 0xA; to the output string
len equ $ - msg; wordlength
section .text; declaration code segment
Global _start; designated entry function
_start :; string displayed on the screen
mov edx, len; three parameters: string length
mov ecx, msg; two parameters: the string to display
mov ebx, 1; a parameter: the file descriptor (stdout)
mov eax, 4; system call number (SYS_WRITE)
int 0x80; call the kernel function
; exit the program
mov ebx, 0; one parameter: the exit code
mov eax, 1; system call number (sys_exit)
int 0x80; calls the kernel function

Compile

NASM uses a parser written manually, so execution speed much faster than GAS, more importantly, it uses the Intel assembler syntax can be used to compile assembler with Intel syntax written

nasm -f elf64  hello.asm  # 32位改成 elf32       产生hello.o

link

The assembler generates object code is not run directly on the computer, it must be processed to generate executable code linker.

ld -s -o hello   hello.o

run

./hello                   #屏幕上打印出 "Hello,world"
Released four original articles · won praise 5 · Views 324

Guess you like

Origin blog.csdn.net/weixin_42007043/article/details/104770950
Recommended