码迷,mamicode.com
首页 > 系统相关 > 详细

AT&T Assembly for Linux and Mac (sys_write)

时间:2015-04-15 23:09:22      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

Write() in C : (sys_write.c)

#include <stdio.h>

int main(void)
{
    printf("Hello Landpack\n");
    return 0;
}

 

技术分享

 

Write() in AT&T for Linux:(sys_write.s)

.section .data

_data:  .ascii "Hello Landpack\n"

        len = .-_data

.section .text

.globl  _start

_start:

        movl    $4,     %eax    #for write
        movl    $_data, %ecx    #The address of data
        movl    $len,   %edx    #The len of string
        movl    $0,     %ebx    #exit with 0
        int     $0x80

        movl    $1,     %eax    #sys_exit
        movl    $0,     %ebx    #exit with 0
        int     $0x80

 

技术分享

 

Write() in AT&T for Mac: (sys_write.s):

.globl _main

_main:

    pushq   %rbp
    #movq   %rsp,   %rbp
    leaq    _data(%rip),%rdi
    callq   _puts
    xorl    %eax,   %eax
    popq    %rbp
    ret 

.section    _TEXT,_cstring,cstring_literals

_data:

    .ascii  "Hello Landpack"

技术分享

AT&T Assembly for Linux and Mac (sys_write)

标签:

原文地址:http://www.cnblogs.com/landpack/p/4430407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!