title: syscall OSX create file [open]
body: <p>I intend to create a file using Mac system calls (OS X and not the bios for now). Everything compiles well, but the result that should be the creating the file <strong>"fileName db "Teste.txt", 0xA, 0x0"</strong> is not realized and I do not understand. can you help me, I also post you the source code compiled with nasm
  Thank you in advance for your answers.</p>
  
  <pre> 
  <code>
  ;------------------------------------------------------------------------------
  ; TITLE: SOURCE.ASM
  ;------------------------------------------------------------------------------
  
  bits 64
  
  ;------------------------------------------------------------------------------
  ;   Definition des syscall
  ;------------------------------------------------------------------------------
  %define _stdout         0x1
  %define _stderr         0x2
  
  %define O_RDONLY        0x0000          ; open for reading only
  %define O_WRONLY        0x0001          ; open for writing only
  %define O_RDWR          0x0002          ; open for reading and writing
  %define O_ACCMODE       0x0003          ; mask for above modes
  %define O_CREAT         0x0200          ; create if nonexistant 
  %define O_TRUNC         0x0400          ; truncate to zero length 
  %define O_EXCL          0x0800          ; error if already exists
  
  %define syscall_write   0x2000004
  %define syscall_exit    0x2000001
  %define syscall_open    0x2000005
  %define syscall_close   0x2000006
  
  ;------------------------------------------------------------------------------
  ;   Section code
  ;------------------------------------------------------------------------------
  section .text
  
  global start
  
  start:
  
      xor rax, rax
      xor rbx, rbx
      mov rbx, fileName
      push mode_f
      push FLAGS
      push rbx
      syscall
      pop rax
  
      xor rbx, rbx
      mov rbx, rax
      mov rax, syscall_exit
      mov rdi, rbx
      syscall
  
  
  f_open_file:
      mov rbp, rsp
      push rbp
      xor rax, rax
      mov rax, syscall_open
      mov rdi, [rbp+8]
      mov rsi, [rbp+16]
      mov rdx, [rbp+24]
      syscall
      pop rax
  
      if: cmp rax, -1
          jge else
          mov rbx, rax
          mov rax, syscall_close
          mov rdi, rbx
          syscall
          pop rax
          ret
      else:
          xor rbx, rbx
          mov rbx, MsgErrr
          push size_err
          push rbx
          call f_print_data
          xor rax, rax
          mov rax, -1
          ret
  
  f_print_data:
      mov rbp, rsp
      push rbp
      mov rax, syscall_write
      mov rdi, _stdout
      mov rsi, [rbp+8]
      mov rdx, [rbp+16]
      syscall
      xor rax, rax
      ret
  
  
  ;------------------------------------------------------------------------------
  ;   Section Data
  ;------------------------------------------------------------------------------
  
  section .data
      fileName    db "Teste.txt", 0xA, 0x0
      MsgErrr     db "Erreur open File", 0xA, 0x0
      size_file   equ ($-fileName)
      size_err    equ ($-MsgErrr)
      mode_f      equ 0777
      FLAGS       equ 0xA02 ;( O_RDWR| O_CREAT| O_EXCL )
  </code></pre>