Compilation basic syntax

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.