title: Comparisons in NASM Assembly 64bit Linux
body: <p><br>
  I am learning Assembler with the book <strong>Programming from the Ground Up</strong> (<a href="http://download-mirror.savannah.gnu.org/releases/pgubook/ProgrammingGroundUp-1-0-booksize.pdf" rel="nofollow">Link</a>) by Jonathan Bartlett and I try to convert the 32bit AT&amp;T Syntax to the 64bit Intel Syntax version as I go. I use NASM. Right now I am struggeling to get the second program of chapter 3 (return the maximum number of a sequence of numbers) to work in 64bit Intel. I have tinkered around a lot with the code and finally managed to narrow down the problem: It's the comparison of two numbers and the conditional jump. This is a very simple version that demonstrates the problem:</p>
  
  <pre><code>section .data
    data: db 0
  
  section .text
    global _start
  
  _start:
    mov rdi, [data] ; if I exit here, the return value (=rdi) is 0
    cmp rdi, 0
    je  .equals     ; this is not executed
    jz  .equals     ; this neither
    jmp .notEquals
  
  .equals:
    mov rax, 60
    mov rdi, 1
    syscall
  
  .notEquals:       ; this is the result I get
    mov rax, 60
    mov rdi, 2
    syscall
  </code></pre>
  
  <p>I read a number from memory (data, the number is 0). But when I compare this 0 with 0, the computer obviously sees a difference I can't see. I am sure that rdi contains 0 at this moment because when I exit the program there and get it's return value with</p>
  
  <pre><code>echo $?
  </code></pre>
  
  <p>it prints 0. I would be very grateful if somebody has any hints about this mysterious behaviour. Also, if you know a nice tool for debugging assembler code, let me know as well because rewriting the program all the time just to get the values of the registers at each moment is very annoying...</p>
  
  <p>PS: I know that the Intel syntax is not commonly used for Linux but I chose it because it looks cleaner to me and also the source highlighting in Vim is much better for NASM than for AT&amp;T ;-)</p>