[Original]linux simple Beauty (ii)

Source: Internet
Author: User

Original link: Linux simple beauty (ii)

We saw in the previous chapter how to do simple things with syscall, and now we see if we can directly invoke the functions in the C standard library to do some "complex" things quickly:

1 Section . Data2FT DB"Now is %d",Ten3 4 Section . Text5 extern puts6 extern exit7 extern sleep8 extern printf9 Global MainTen  One Main: A     movEdi One - again:     -     DecEDI the     PushEDI -     Pushft -     Pagerprintf -      +     Push 1 -     PagerSleep +      A     CMPEdi0 at     jnzagain -  -     Pushmsg -     Pagerputs -      -     Push 0 in     PagerExit -      to msg: +Db"Happy xxx day!",0

The above code is simple, counting from 10 to 0, then printing one line and ending. Unlike the previous code, the function in the C standard library is called. The compilation is the same as before:

Nasm-e elf Main.asm

Let's see how to connect:

Gcc-m32-o Main MAIN.O

Good bird! It is important to note that my OS is ubuntu64, and the ASM code is 32 bits, if you start with ld-m elf_i386-lc-o main MAIN.O, you will first be prompted to find the C library, then you can enter/usr/lib, then use:

sudo ln-sv/lib/i386-linux-gun/libc.so.6 libc.so

Create a soft connect fix. But at run time prompt cannot find executable file! The file is clearly in the! Then connect with GCC, but to change the _start to main and load 32 libraries:

sudo apt-get install Ia32-libs

You will also be prompted not to find the H file, and then load the library:

sudo apt-get install G++-multilib

There are also 2 family libraries that can be loaded if necessary:

sudo apt-get install libc6:i386 libgcc1:i386 gcc-4.6-base:i386

Libstdc++5:i386 libstdc++6:i386

sudo apt-get install libc6-i386

Finally, some C code when compiling with STD=C99 will find that the hint can not get the structure size, then change to the following:

Gcc-d_gnu_source-std=c99 MAIN.C

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.