As
Aus Tuxfutter
As ist der Assembler für Linux.
Ein Beispiel für den Mount-Befehl:
## mount.s ###################################################
## Mathias Weidner ############################################
## http://weidner.in-bad-schmiedeberg.de/ ######################
## This file contains minimal program to mount a CD.
##
## It takes three arguments: device, mount point, filesystem
##
## example:
## mount /dev/cdrom /mnt/cdrom iso9660
## Compile Instructions:
## -------------------------------------------------------------
## as -o cdmount.o cdmount.s
## ld -O0 -o cdmount cdmount.o
########################################################################
.section .data
.align 4
mountdata:
.long 0
########################################################################
.section .text
.globl _start
.align 4
_start:
movl %esp, %ebp # store %esp in %ebp
_mount:
addl $8, %esp # %esp ---> second parameter on stack
movl (%esp), %ebx # move next parameter into %ebx
addl $4, %esp # %esp ---> third parameter on stack
movl (%esp), %ecx # move next parameter into %ecx
addl $4, %esp # %esp ---> fourth parameter on stack
movl (%esp), %edx # move next parameter into %edx
# movl $0xc0ed0001, %esi # MS_MGC_VAL|MS_RDONLY ---> %esi
movl $0xc0ed0080, %esi # MS_MGC_VAL | S_WRITE
leal mountdata, %edi # pointer to 0
movl $21, %eax # system call _mount
int $0x80
_exit:
movl %eax, %ebx # give back return value
xorl %eax, %eax # %eax = 0
incl %eax # %eax = 1, system call _exit ()
int $0x80 # execute _exit () system call
## end of cdmount.s ############################################
In diesem Beispiel sieht man auch, dass mit Hilfe von as der Quellcode zunächst in eine Objektdatei überführt wird. Mit Hilfe von ld wird dann die Datei zu einem fertigen, ausführbaren Programm gelinkt. Das fertige Programm hat übrigens eine Größe von nur 835 Bytes.

