All pastes #2083074 Raw Edit

Untitled

public text v1 · immutable
#2083074 ·published 2011-09-26 15:56 UTC
rendered paste body
# hello.S - simple assembler for Linux

# registers for system call arguments : ebx ecx edx esi edi ebp
# return value in eax

#include <asm/unistd.h>
#include <linux/limits.h>     

/* Some constants */

#define KERNEL    0x80        
#define NEWLINE   '\n'
#define STDOUT    1
#define OK_EXIT   0

.data                         # Section declaration
msg:
  .string "Hello, world !\n"  # Usual message
  len = . - msg               # Message length

.text                         # Section declaration
  .global _start              # Export entry point for linker

_start:

# Write string to stdout ...

  movl  $STDOUT, %ebx         # 1st arg : fd
  movl  $msg, %ecx            # 2nd arg : pointer to message
  movl  $len, %edx            # 3rd arg : message length
  movl  $__NR_write, %eax     # System call number
  int   $KERNEL               # Call kernel

# And exit ...

  movl  $OK_EXIT, %ebx        # 1st arg : exit code
  movl  $__NR_exit, %eax      # System call number
  int   $KERNEL               # Call kernel