title: NASM Hello World Segmentation Fault
body: <p>So yeah, I am tinkering with assembly level programming...</p>
  
  <p>Here is what I have so far.</p>
  
  <pre><code>global _start
  
  section .text
  _start:
  
      mov eax, 4      ; write
      mov ebx, 1      ; stdout
      mov ecx, msg
      mov edx, msg.len
      int 0x80        ; system call
  
  
      mov eax, 1      ; exit
      mov ebx, 0      ; exit code
      int 0x80        ; system call
  
  section .data
  
      msg: db "Hello world!", 10  ; Defines the string "Hello world!\n"
      .len equ $-msg
  </code></pre>
  
  <p>How does the statement <code>.len equ $-msg</code> work? I understand this is the length of the string. I also know that equ is like <code>#define</code> in C. So this variable does not exist in memory, it is put in place by the assembler. (nasm)</p>
  
  <p>What does the $ symbol do, and is that a subtraction occurring afterwards?</p>
  
  <p><s> My output causes a segfault, I am hoping I will be able to fix this myself when I understand the <code>.len equ $-msg</code> syntax. </s> I have fixed the fault, but still don't understand the $ notion.</p>
  
  <p><strong>EDIT</strong> <s> Segfault caused by this being a malformed program. </s> Fixed</p>