The assembler consists of three parts:
Data segment BSS paragraph text
Data segment:
Used to declare data segments that initialize data or constants, this data does not change at run time.
syntax for declaring data segments:
Section. Data
BSS segment:
The BSS segment declares the variable.
Declaration syntax:
Section. BSS
Text segment:
Save the actual code.
The required declaration at the beginning of this paragraph global_start: tell the kernel program to start executing the code.
Declaring text snippet Syntax:
Section. Text
Global _start
_start:
Comments:
Comments with semicolons:;
Assembly language Statements:
Three different types:
Executable instructions: Tell the processor what to do
Assembly directives: telling the compilation of various aspects of the assembly process
Macro: Text substitution
Assembly language Syntax:
[lable] mnemonic [operands] [; Comment]
assembly Language Output Hello World:
Input content:
vim hello.asm ; Create a hello.asm file
nasm-f elf hello.asm ; assemble the program to form a hello.o file
ld-m elf_i386-s-o hello hello.o ; link and create an executable hello
./hello ; Execution procedure
Content of Hello.asm:
Section . Text global _start_start: mov Edx,len mov ecx,msg mov ebx,1 mov eax,4 int 0x80 mov eax,1 int 0x80section. Data 'Hello, World', 0xa len equ $-Msg
Section.Text, declared here as a paragraphGlobal_startThis section must be declared to tell the kernel program to start executing_start: ;Tell the linker here to program entry Movedx,Len;Information length MOVECX,Msg;Write the information movebx,1 ; Document descriptionMoveax,4 ;System call number(Sys_write) Int0x80 call kernel moveax,1 ;< Span class= "PLN" >system call number (sys_exit int0x80call kernelsection. ' Hello, world! ' , 0xa information len equ $ - msg ; information length
This section references: http://www.yiibai.com/html/assembly/2013/0812118.html
Compilation basic syntax