#PURPOSE: Simple program that exits and returns a
# status code back to the Linux kernel
#
#INPUT: none
#
#OUTPUT: returns a status code. This can be viewed
# by typing
#
# echo $?
#
# after running the program
#
#VARIABLES:
# %eax holds the system call number
# %ebx holds the return status
#
.section .data
.section .text
.globl _start
_start:
movl $1, %eax # this is the linux kernel command
# number (system call) for exiting
# a program
movl $4, %ebx # this is the status number we will
# return to the operating system.
# Change this around and it will
# return different things to
# echo $?
int $0x80 # this wakes up the kernel to run
# the exit command
$ as test.s -o test.o
$ ld test.o -o test
$ ./test
$ echo $?
====== GCC Inline Assembly ======
asm (""
: 輸出暫存器 // "=r"
: 輸入暫存器 // "r"
: 會被修改到的暫存器 (clobber));
asm ("nop");
__asm__("movl $1, %eax\n\t"
"movl $4, %ebx\n\t"
"int $0x80");
* [[http://learn.akae.cn/media/ch19s05.html|5. C内联汇编]]
* [[http://sourceware.org/binutils/docs-2.22/as/index.html|Using as]]
* [[http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html|GCC-Inline-Assembly-HOWTO]]
* [[http://www.ethernut.de/en/documents/arm-inline-asm.html|ARM GCC Inline Assembler Cookbook]]
====== x86 ======
* [[http://learn.akae.cn/media/ch18.html|第 18 章 x86汇编程序基础]]
* [[wp>x86 assembly language]]
* [[wb>x86 Assembly]]
* [[http://www.acm.uiuc.edu/sigwin/old/workshops/winasmtut.pdf|Windows Assembly Programming Tutorial]]
Intel (NASM):
mov eax, 4 ; mov 目標 源
AT&T (GAS):
mov $4, %eax; mov 源 目標
====== 6502 ======
====== 外部連結 ======
* [[http://learn.akae.cn/media/ch18.html|第 18 章 x86汇编程序基础]]
* [[http://tldp.org/HOWTO/Assembly-HOWTO/|Linux Assembly HOWTO]]
* [[wp>Assembly language]]
* [[wp>Netwide Assembler]]
* [[http://www.nasm.us/|The Netwide Assembler]]
* [[http://www.ibm.com/developerworks/cn/linux/l-gas-nasm.html|Linux 汇编器:对比 GAS 和 NASM]]
* [[http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html|GCC-Inline-Assembly-HOWTO]]
* [[http://asm.sourceforge.net/articles/linasm.html|Using Assembly Language in Linux]]
* [[http://www.reversing.be/article.php?story=20051203194931893|Inline Assembly On GCC using Intel Syntax]]