您的位置:首页 > 运维架构 > Linux

AT&T Assembly for Linux and Mac (sys_write)

2015-04-15 22:11 639 查看
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"


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: