title: Reading filename from argv via x86 assembly
body: <p>I'm and trying to read a filename passed to my executable and write to that file using assembly. It compiles without error but fails when executed. What is wrong with my code exactly?</p>
  
  <pre><code>BITS 32
  segment .data
  text db "text"
  
  segment .text
  
  global main
  
  main:
  pop ebx 
  pop ebx
  pop ebx    ; pop pointer to filename into ebx
  mov eax,0x5  ;syscall open
  mov ecx,0x2   ;flag read/write
  int 0x80   ;call kernel
  mov ebx,eax   ;save returned file descriptor
  mov eax,0x4 ; write syscall
  mov ecx,text ;mov pointer to text into ecx
  mov edx,0x4 ;string length
  int 0x80  ;exit syscall
  mov eax,0x1
  int 0x80
  </code></pre>