[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
-
- . Data
-
- Message:. String"Hello! \ N"
-
- Length =.-Message
-
-
- . Text
-
- . Global _ start
-
-
- _ Start:
- Movl $ length, % edX
-
- Movl $ message, % ECx
-
- Movl $1, % EBX
-
- Movl $4, % eax
-
- Int$0x80
-
-
- Movl $0, % EBX
-
- Movl $1, % eax
-
- 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
-
- 08048074 <_ Start>:
-
- . Text
-
- . Global _ start
-
-
- _ Start:
-
- Movl $ length, % edX
- 8048074: BA 08 00 00 00 mov $0x8, % edX
-
- Movl $ message, % ECx
-
- 8048079: B9 9C 90 04 08 mov $ 0x804909c, % ECx
-
- Movl $1, % EBX
-
- 804807e: BB 01 00 00 00 mov $0x1, % EBX
- Movl $4, % eax
-
- 8048083: B8 04 00 00 00 mov $0x4, % eax
-
- Int$0x80
-
- 8048088: CD 80Int$0x80
-
- Movl $0, % EBX
-
- 804808a: BB 00 00 00 00 mov $0x0, % EBX
-
- Movl $1, % eax
-
- 804808f: B8 01 00 00 mov $0x1, % eax
-
- Int$0x80
- 8048094: CD 80Int$0x80
-
- RET
-
- 8048096: C3 RET
-