linux 彙編 hello world + 調試

來源:互聯網
上載者:User
.section .data#初始化的變數  output:     .ascii "hello,world\n"     #要列印的字串,.data為初始化值的變數。output是標籤,指示字串開始的位置,ascii為資料類型  .section .bss#未初始化的變數,由0填充的緩衝區     .lcomm num,20     #lcomm為本地記憶體地區,即本地彙編外的不能進行訪問。.comm是通用記憶體地區。  .section .text#組合語言指令碼     .globl _start#啟動入口     _start:     movl $4,%eax#調用的系統功能,4為write        movl $output,%ecx#要列印的字串     movl $1,%ebx#檔案描述符,螢幕為1        movl $12,%edx#字串長度     int $0x80#顯示字串hello,world          movl $0,%eax     movl $num,%edi     movl $65,1(%edi)#A 的ascii     movl $66,2(%edi)#B 的ascii      movl $67,3(%edi)#C 的ascii      movl $68,4(%edi)#D 的ascii     movl $10,5(%edi)#\n的ascii           movl $4,%eax#調用的系統功能,4為write         movl $num,%ecx#要列印的字串       movl $1,%ebx#檔案描述符,螢幕為1        movl $6,%edx#字串長度     int $0x80#顯示字串ABCD                movl $1,%eax#1為退出     movl $0,%ebx#返回給shell的結束代碼值       int $0x80#核心非強制中斷,退出系統  

效果及調試, -gstabs用於產生調試資訊

 

deepfuture-lx@deepfuture-lx-desktop:~/private/mytest$ as -gstabs -o hello.o hello.s

deepfuture-lx@deepfuture-lx-desktop:~/private/mytest$ ld -o hello 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 <http://gnu.org/licenses/gpl.html>

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#初始化的變數

2 output:

3   .ascii "hello,world\n"

4   #要列印的字串,.data為初始化值的變數。output是標籤,指示字串開始的位置,ascii為資料類型

5 .section .bss#未初始化的變數,由0填充的緩衝區

6   .lcomm num,20

7   #lcomm為本地記憶體地區,即本地彙編外的不能進行訪問。.comm是通用記憶體地區。

8 .section .text#組合語言指令碼

9   .globl _start#啟動入口

10   _start:

(gdb) run

Starting program: /home/deepfuture-lx/private/mytest/hello 

hello,world

ABCD

 

Program exited normally.

(gdb)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.