C Language Development in Linux (at&t assembly language) 04

Source: Internet
Author: User

[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]

It is also a x86 CPU, but it can be expressed in different forms of assembly languages. In Windows, we use intel-format assembly languages, while in Linux systems, at&t-format assembly languages are often used. What is at&t format assembly?CodeWhat about it? Let's write a try.

[CPP] View plaincopy
  1. . Data
  2. Message:. String"Hello! \ N"
  3. Length =.-Message
  4. . Text
  5. . Global _ start
  6. _ Start:
  7. Movl $ length, % edX
  8. Movl $ message, % ECx
  9. Movl $1, % EBX
  10. Movl $4, % eax
  11. Int$0x80
  12. Movl $0, % EBX
  13. Movl $1, % eax
  14. Int$0x80

This is a simple assembly file. We can compile it in two steps. First, enter as-ststabs-O hello. O hello. s, and then enter LD-O hello. O. To verify whether the execution file is correct, enter./hello to verify.

In the as command, because we use the-gstabs option, debugging information is contained in the hello execution file. Therefore, if you want to debug in one step, you can input GDB hello for debugging.

So what is the code for the disassembly of the hello execution file? Enter objdump-s-d hello.

[CPP] View plaincopy
  1. 08048074 <_ Start>:
  2. . Text
  3. . Global _ start
  4. _ Start:
  5. Movl $ length, % edX
  6. 8048074: BA 08 00 00 00 mov $0x8, % edX
  7. Movl $ message, % ECx
  8. 8048079: B9 9C 90 04 08 mov $ 0x804909c, % ECx
  9. Movl $1, % EBX
  10. 804807e: BB 01 00 00 00 mov $0x1, % EBX
  11. Movl $4, % eax
  12. 8048083: B8 04 00 00 00 mov $0x4, % eax
  13. Int$0x80
  14. 8048088: CD 80Int$0x80
  15. Movl $0, % EBX
  16. 804808a: BB 00 00 00 00 mov $0x0, % EBX
  17. Movl $1, % eax
  18. 804808f: B8 01 00 00 mov $0x1, % eax
  19. Int$0x80
  20. 8048094: CD 80Int$0x80
  21. RET
  22. 8048096: C3 RET

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.