加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 没有使用库的Hello world

发布时间:2020-05-23 03:02:52 所属栏目:Linux 来源:互联网
导读:这是一个现场采访问题,我很困惑. 我被要求为linux编写一个Hello世界程序 而不使用系统中的任何库.我想我必须使用 系统调用或某些东西..代码应该使用-nostdlib和 -nostartfiles选项.. 如果有人可以帮助,会很好 $cat hwa.Swrite = 0x04exit = 0xfc.text_start:

这是一个现场采访问题,我很困惑.

我被要求为linux编写一个Hello世界程序
而不使用系统中的任何库.我想我必须使用
系统调用或某些东西..代码应该使用-nostdlib和
-nostartfiles选项..

如果有人可以帮助,会很好

解决方法

$cat > hwa.S
write = 0x04
exit  = 0xfc
.text
_start:
        movl    $1,%ebx
        lea     str,%ecx
        movl    $len,%edx
        movl    $write,%eax
        int     $0x80
        xorl    %ebx,%ebx
        movl    $exit,%eax
        int     $0x80
.data
str:    .ascii "Hello,world!n"
len = . -str
.globl  _start
$as -o hwa.o hwa.S
$ld hwa.o
$./a.out
Hello,world!

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读