"Fossies" - the Fresh Open Source Software Archive

Member "fasm/examples/elfexe/hello64.asm" (9 Feb 2020, 716 Bytes) of package /linux/misc/fasm-1.73.22.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Generic Assembler source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 ; fasm demonstration of writing 64-bit ELF executable
    3 ; (thanks to František Gábriš)
    4 
    5 ; syscall numbers: /usr/src/linux/include/asm-x86_64/unistd.h
    6 ; parameters order:
    7 ; r9    ; 6th param
    8 ; r8    ; 5th param
    9 ; r10   ; 4th param
   10 ; rdx   ; 3rd param
   11 ; rsi   ; 2nd param
   12 ; rdi   ; 1st param
   13 ; eax   ; syscall_number
   14 ; syscall
   15 
   16 format ELF64 executable 3
   17 
   18 segment readable executable
   19 
   20 entry $
   21 
   22     mov edx,msg_size    ; CPU zero extends 32-bit operation to 64-bit
   23                 ; we can use less bytes than in case mov rdx,...
   24     lea rsi,[msg]
   25     mov edi,1       ; STDOUT
   26     mov eax,1       ; sys_write
   27     syscall
   28 
   29     xor edi,edi     ; exit code 0
   30     mov eax,60      ; sys_exit
   31     syscall
   32 
   33 segment readable writeable
   34 
   35 msg db 'Hello 64-bit world!',0xA
   36 msg_size = $-msg