linux 汇编 hello world + 调试

.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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值