Index of /~bobmon

[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[DIR]0.current/24-Jan-2012 10:43 -  
[DIR]110/06-Dec-2011 15:42 -  
[DIR]240/06-Dec-2011 17:32 -  
[DIR]330/26-Jan-2012 06:38 -  
[DIR]375/09-Dec-2011 06:53 -  
[DIR]476/26-Jan-2012 09:20 -  
[DIR]491/25-Jan-2012 11:24 -  
[DIR]ACM/24-Mar-2010 12:08 -  
[DIR]BloomU/24-Mar-2010 12:07 -  
[DIR]Code/30-Dec-2011 21:48 -  
[DIR]Computer-Organization/06-Feb-2011 15:46 -  
[DIR]Download/28-Jan-2011 22:02 -  
[DIR]Graphics/12-Jan-2012 06:22 -  
[DIR]Humor/24-Mar-2010 12:08 -  
[DIR]Index/27-Sep-2010 15:44 -  
[DIR]Information/05-Dec-2011 16:22 -  
[DIR]Linux-distros/13-May-2010 12:48 -  
[DIR]Maps/23-May-2007 14:32 -  
[DIR]Multimedia/13-May-2010 12:34 -  
[DIR]Nasm-Win32/06-Nov-2008 16:02 -  
[DIR]Networking/26-Jan-2012 14:05 -  
[DIR]Ophcrack Tables/04-Aug-2009 13:17 -  
[   ]PACISE-board.zip18-Sep-2009 08:02 706K 
[DIR]PACISE/24-Mar-2010 12:08 -  
[   ]Pacise-Old.zip28-Sep-2006 22:50 39M 
[DIR]PalmOS/24-Mar-2010 12:07 -  
[DIR]Personal/02-Feb-2011 20:38 -  
[DIR]Presentations/05-Dec-2011 14:02 -  
[TXT]README.html24-Mar-2010 12:08 8.8K 
[DIR]Readings/24-Mar-2010 12:08 -  
[DIR]Reference/10-Sep-2011 15:44 -  
[DIR]Screenshots/29-Sep-2009 08:41 -  
[DIR]Semesters/12-Jan-2012 14:34 -  
[DIR]Software/24-Jan-2012 08:00 -  
[DIR]Webpages/26-Oct-2010 21:34 -  
[   ]apache2conf.man27-Sep-2010 18:24 12K 
[DIR]cgi-bin/11-Oct-2011 09:54 -  
[DIR]css/07-Jan-2012 06:47 -  
[DIR]includes/20-Aug-2011 07:25 -  
[DIR]js/26-Jan-2012 08:37 -  
[DIR]professional/28-Oct-2008 15:25 -  
[TXT]sched-Semester.html24-Mar-2010 12:08 2.1K 

Linux Assembly tutorial

Linux Assembly tutorial

This is a basic introduction to using Assembly language on a Linux system. It assumes at least a little general programming and Linux experience. Some references to further information are provided at the end.

i386 Linux and x86-64 Linux are treated differently, because i386 (IA-32) processors are different from x86-64 (AMD64/Intel 64) processors. IA-64 processors, e.g. Itanium, are are even more different, and are not considered here.

A simple Assembly program:

"Hello, world" using a Linux kernel call

This program depends on a Linux system call, int 0x80. (An equivalent DOS/Windows version would use the DOS call, int 0x21.) The call is the same in both i386 and x86-64 versions of Linux, so this program works in either (when assembled and linked appropriately).

; hello.asm complete program
;
; from <http://www.csee.umbc.edu/help/nasm/nasm.shtml>
; 2009-11-18
;
;  The nasm source code is hello.asm
;  This demonstrates basic text output to a screen.
;
;  hello.asm  a first program for nasm for Linux, Intel, gcc
;
; 32-bit (i386) ---
;       assemble:       nasm  -f elf32  -l hello.lst  hello.asm
;       link:           ld   -m elf_i386  -o hello  hello.o
;         or:           gcc  -o hello  hello.o  (only on 32-bit installations)
;
; 64-bit (x86-64/amd64) ---
;       assemble:       nasm  -f elf64  -l hello.lst  hello.asm
;       link:           ld   -m elf_x86_64  -o hello  hello.o
;         or:           gcc  -o hello  hello.o  (only on 64-bit installations)
;
; run:          hello 
; output is:    Hello World 
;
        SECTION .data          ; data section
msg:    db "Hello World",10        ; the string to print, 10=cr
len:    equ $-msg          ; "$" means "here"
                                ; len is a value, not an address

        SECTION .text          ; code section
        global main             ; make label available to linker as invoked by gcc
        global _start           ; make label available to linker w/ default entry
main:                           ; standard  gcc  entry point
_start:

        mov    edx,len            ; arg3, length of string to print
        mov    ecx,msg            ; arg2, pointer to string
        mov    ebx,1              ; arg1, where to write, screen
        mov    eax,4              ; write command to int 80 hex
        int    0x80               ; interrupt 80 hex, call kernel

        mov    ebx,0              ; exit code, 0=normal
        mov    eax,1              ; exit command to kernel
        int    0x80               ; interrupt 80 hex, call kernel

Assemble, link a file for i386 Linux:

nasm -f elf -o hello-elf.o hello.asm
Now build the executable, "hello":
ld -m elf_i386 -o hello --entry=main hello-elf.o # specify the desired entry point, such as "main"
or
ld -m elf_i386 -o hello hello-elf.o # ld will look for a default entry point of "_start"
or, on a native 32-bit system:
ld -m elf -o hello hello-elf.o # ld will use the appropriate version of the elf format

Assemble, link a file for x86-64 Linux:

nasm -f elf64 -o hello-64.o hello.asm
Now build an executable, "hello-64":
ld -m elf_x86_64 -o hello-64 --entry=main hello-64.o # specify the desired entry point, such as "main"
or
ld -m elf_x86_64 -o hello-64 hello-64.o # ld will look for a default entry point of "_start"
or, on a native 64-bit system:
ld -m elf -o hello-64 hello-64.o # ld will use the appropriate version of the elf format
or let "gcc" invoke "ld":
gcc -o hello-64 hello-64.o # gcc uses entry point "main"