-
Xcode 环境下的汇编与 C/C++/ObjC (下) - [苹果汇编]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://51test2003.blogbus.com/logs/32869062.html
汇编代码 function.s.data # beginning of our data section
msg : .ascii "This function is in AT&T asm file!\n" # string with a carriage- return
len = . - msg # string length in bytes
.text # start of the code indicator
.globl _print_info_s
_syscall: # declaring a kernel call function
int $0x80 # make the system call
ret # return to the caller
_print_info_s: # entry point for linker
# write our string to standard output
pushl $len # message length
pushl $msg # message to write
pushl $0x1 # file descriptor value
movl $0x4, %eax # system call number (sys_write)
call _syscall # call the kernel
addl $12, %esp # clean the stack
ret
汇编代码 funtions.nasmsection .text ; start of the code indicator
global _print_info_nasm ; make the main function externally visible
section .data ; beginning of our data section
msg db "This function is in Intel nasm file!",0xa ; string with a carriage- return
len equ $ - msg ; string length in bytes
_syscall: ; declaring a kernel call function
int 0x80 ; make the system call
ret ; return to the caller
_print_info_nasm: ; entry point for linker
; write our string to standard output
push dword len ; message length
push dword msg ; message to write
push dword 1 ; file descriptor value
mov eax, 0x4 ; system call number (sys_write)
call _syscall ; call the kernel
add esp, 12 ; clean the stack
ret
头文件 asm.h/** asm.h
* testss
*
* Created by shijing on 08-12-22.
* Copyright 2008 石静. All rights reserved.
*
*/
int print_info_nasm();
int print_info_s();测试入口 main.c/** main.c
* testss
*
* Created by shijing on 08-12-22.
* Copyright 2008 石静. All rights reserved.
*
*/
#include <stdio.h>
#include "asm.h"
int main()
{
print_info_nasm();
print_info_nasm();
print_info_s();
return 0;
}
随机文章:
Xcode 环境下的汇编与 C/C++/ObjC (上) 2008-12-23Xcode 单元测试介绍 (C/C++ 篇) 2008-12-24Xcode 单元测试介绍 (Objective C 篇) 2008-12-24Cocoa 教程 第一讲 Objective C 语法(一) 2007-08-27
收藏到:Del.icio.us