Pejman Moghadam / Assembly

Linux Assembly - Hello World

Public domain


; Filename: hello.asm
; Compile : nasm -f elf hello.asm -l hello.lst
; Link    : ld -s -o hello hello.o
; Debug   : ald hello
; Disasm  : objdump -M intel -D hello
; Disasm  : ndisasm -u hello
; Dump    : hexdump -C hello
; Syscall : strace ./hello
; Syscall : /usr/include/asm-i386/unistd.h
; Syscall : /usr/src/linux/arch/i386/kernel/entry.S
; Manual  : man 2 write  
; Desc    : ssize_t write( int fd, 
;                          const void *buf, 
;                          size_t count);
; Register: ebx=(int fd),
;           ecx=(const void *buf), 
;           edx=(size_t count);

section .data
msg      db      "Hello World !!!",0xa
len      equ     $ - msg

section .text
global _start
_start:

;write our string to stdout
        mov     edx,len ;third argument:  message length
        mov     ecx,msg ;second argument: pointer to message
        mov     ebx,1   ;first argument:  file handle (stdout)
        mov     eax,4   ;system call number (sys_write)
        int     0x80    ;call kernel

;and exit
        mov     ebx,0   ;first syscall argument: exit code
        mov     eax,1   ;system call number (sys_exit)
        int     0x80    ;call kernel

BY: Pejman Moghadam
TAG: asm, hello-world
DATE: 2008-08-06 19:29:48


Pejman Moghadam / Assembly [ TXT ]