您当前的位置: 首页 >  linux

linux简单之美(二)

发布时间:2012-12-30 11:43:57 ,浏览量:0

    我们在前一章中看到了如何仅仅用syscall做一些简单的事,现在我们看能不能直接调用

C标准库中的函数快速做一些"复杂"的事:

section .data
	ft db "now is %d",10

section .text
extern puts
extern exit
extern sleep
extern printf
global main

main:
	mov edi,11
again:	
	dec edi
	push edi
	push ft
	call printf
	
	push 1
	call sleep
	
	cmp edi,0
	jnz again

	push msg
	call puts
	
	push 0
	call exit
	
msg:
 db "happy xxx day!",0

以上代码功能很简单,从10倒数到0,然后打印一行,最后结束.与之前代码不同的是其中

调用了C标准库中的函数.编译和以前一样:

nasm -e elf main.asm

我们看看怎么连接:

gcc -m32 -o main main.o

好鸟!运行正常.

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    107766博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0482s