Using assembly language to write Hello world! under Linux Program

Source: Internet
Author: User

Recently, the company needs to complete security testing, resulting in the need for more in-depth study of attack methods and vulnerability analysis of the technology, the total feel a bit like a hacker:), but not only to know some of the security testing tools and tools to use, but also need basic Kung Fu, first from the University of the Assembly language (hehe, university lessons, For a long time did not use most of the teachers had to start.

1. Download NASM installation package

#wget http://www.nasm.us/pub/nasm/releasebuilds/2.11.08/nasm-2.11.08.tar.gz

2, decompression installation NASM

#tar-XZVF nasm-2.11.08.tar.gz

#cd nasm-2.11.08

#./configure

#make

#make Install

3, Write Hello.asm

Section. Data;Section DeclarationMSG db"Hello, world!.", 0xA;Our Dear stringLen Equ $-Msg;length of our dear stringSection. Text;Section Declaration                       ;We must export the entry point to the ELF linker orGlobal _start;Loader. They conventionally recognize _start as their                       ;entry point. Use ld-e foo to override the default._start:;write our string to stdout       moveax4   ;system call Number (Sys_write)       movEbx1   ;First Argument:file handle (stdout)       movEcx,msg;second argument:pointer to message to write       movEdx,len;Third Argument:message length       int0x80;Call kernel;and exit       moveax1   ;system call Number (Sys_exit)       XOREbx,ebx;First syscall argument:exit code       int0x80;Call kernel

4. Compile the connection

#nasm-F elf64 hello.asm (Linux is 64-bit, if 32, use ELF32)

#ld-S-o Hello hello.o

#ls Hello

Hello

5. Execution procedure

#./hello

Hello, world!.

Finally write a simple Hello world, recall some of the functions of common instructions and registers, only in the later security testing and C language to compile, the knowledge of the assembly, knowledge to time to hate less, or more to prepare some knowledge: refueling ~ ~ ~

Using assembly language to write Hello world! under Linux Program

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.