Compile "helloworld" on the x86 Platform"

Source: Internet
Author: User

First, you need to install a assembler. I use NASM, which is very easy to install in Linux.

Nasmhttp: // www. NASM. US/pub/NASM/releasebuilds/

After downloading the file, decompress it and enter the directory to find the configure file. Next, I believe that anyone familiar with Linux will know what to do.

Enter./configure. After the command is executed, you will find that a MAKEFILE file is generated in the directory. This is the make command to compile NASM.

Enter root and enter make install to install NASM. If your machine does not have GCC, you can install GCC and search for it by yourself. Because GCC has been installed here, I will not talk about it here.

 

Next, you can compile the helloworld assembly code. Here I refer to the sample code on Wikipedia.

  section .data     msg     db      ‘Hello, world!‘,0xA     len     equ     $-msg      section .text global  _start _start:         mov     edx,len         mov     ecx,msg         mov     ebx,1         mov     eax,4         int     0x80          mov     ebx,0         mov     eax,1         int     0x80

Then save the edited file. It does not matter if the initial suffix is used. The suffix is only displayed in Linux. After saving it, enter the NASM-F elf32 file name, after the command is executed

A file named. O is generated, and after the input LD file name. O-o file name is completed, the executable file we normally use is generated.

At this time, the input./file name will show Hello world.

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.