Linux compilation Hello world + debugging

Source: Internet
Author: User
. Section. Data # initialization variable output:. ASCII "Hello, world \ n" # the string to be printed. Data is the variable of the initialization value. Output is a tag indicating the start position of the string. ASCII is the data type. section. BSS # uninitialized variable, buffer filled by 0. lcomm num, 20 # lcomm is the local memory area, that is, the volume cannot be accessed .. Comm is the general memory area. . Section. text # assembly language instruction code. globl _ start # Start entry _ start: movl $4, % eax # The called system function, 4 is write movl $ output, % ECx # the string to be printed movl $1, % EBX # file descriptor. The screen is 1 movl $12, % edX # String Length int $0x80 # The display string Hello, world movl $0, % eax movl $ num, % EDI movl $65,1 (% EDI) # A's ASCII movl $66,2 (% EDI) # B's ASCII movl $67,3 (% EDI) # c ascii movl $ (% EDI) # d ascii movl $ (% EDI) # \ n ASCII movl $4, % eax # called system functions, 4: Write movl $ num, % ECx # The movl $1, % EBX # file descriptor to be printed. The screen is 1 movl $6, % edX # String Length int $0x80 # display the string ABCD movl $1, % eax #1 is to exit movl $0, % EBX # exit code returned to shell int $0x80 # kernel Soft Interrupt, exit system

Effect and debugging.-ststabs is used to generate debugging information.

 

Deepfuture-lx @ deepfuture-lx-desktop :~ /Private/mytest $ as-gstabs-O hello. O hello. s

Deepfuture-lx @ deepfuture-lx-desktop :~ /Private/mytest $ LD-O hello. o

Deepfuture-lx @ deepfuture-lx-desktop :~ /Private/mytest $./Hello

Hello, world

ABCD

Deepfuture-lx @ deepfuture-lx-desktop :~ /Private/mytest $ GDB hello

Gnu gdb (GDB) 7.1-Ubuntu

Copyright (c) 2010 Free Software Foundation, Inc.

License gplv3 +: gnu gpl Version 3 or later

This is free software: You are free to change and redistribute it.

There is no warranty, to the extent permitted by law. Type "show copying"

And "show warranty" for details.

This GDB was configured as "x86_64-linux-gnu ".

For bug reporting instructions, please see:

<Http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from/home/deepfuture-LX/private/mytest/Hello... done.

(GDB) List

1. Section. Data # initialized variable

2 output:

3. ASCII "Hello, world \ n"

4 # the string to be printed. Data is the variable of the initial value. Output is a tag indicating the start position of the string. ASCII is the data type.

5. Section. BSS # uninitialized variable, buffer filled by 0

6. lcomm num, 20

7 # lcomm is the local memory area, that is, it cannot be accessed outside of the compiler .. Comm is the general memory area.

8. Section. Text # assembly language instruction code

9. globl _ start # Start entry

10 _ start:

(GDB) Run

Starting program:/home/deepfuture-LX/private/mytest/Hello

Hello, world

ABCD

 

Program exited normally.

(GDB)

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.