/*
  program:  HelloWorld.s
  purpose:  traditional "Hello, world!" program, in GAS assembler for linux, in intel syntax
  task:     none
  author:   Matthias Ansorg <matthias@ansorgs.de> for modifications
  licence:  GNU Free Documentation License, Version 1.1; as this code is based on the 
            Linux Assembly HowTo.
  date:     2003-06-14 to 2003-06-14
*/

/* use the following instruction to make the executable:
   as -o HelloWorld.o HelloWorld.s; ld -s -o HelloWorld HelloWorld.o
*/

.intel_syntax noprefix                  /* use intel syntax instead of standard AT&T-Syntax, 
                                           no %register notation */

.data                                   /* data section for read-write data */

msg:
        .ascii  "Hello, world!\n"       /* the traditional string */
        len = . - msg                   /* calculate length of string, "." means address of this 
                                           actual line in machine code */
                                           
.text                                   /* text section for read-only program code */


/* we must export the entry point to the ELF linker or                        	
   loader. They conventionally recognize _start as their
   entry point. Use ld -e foo to override the default.
*/

.global _start                        

_start:

/* write our string to stdout */

        mov    edx, offset len     /* third argument: message length
                                    * why do we use offset here, though len's content is the 
                                    * length? */
        mov    ecx, offset msg     /* second argument: pointer to message to write */
        mov    ebx, 1              /* first argument: file handle (stdout) */
        mov    eax, 4              /* system call number (sys_write) */
        int    0x80                /* call kernel */

/* exit: */

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

