title: Finding number is Even/Odd in assembly
body: <p>I'm trying to find whether a given number (Input by user) is even or odd. </p>
  
  <blockquote>
    <p>I'm simply applying <code>AND</code> operation on binary digits of a no. with <code>1</code>, If the number is odd then operation will result <code>0</code> and we will Output Number is odd, otherwise we will output Number is even. </p>
  </blockquote>
  
  <p>Although logic seems simple, But it's not working in the below code. I'm not getting where is the problem in the code. Can anybody tell me where is the problem</p>
  
  <pre><code>section .data
      userMsg db 'Please enter a number'
      lenuserMsg equ $ - userMsg  
      even_msg db 'Even Number!'
      len1 equ $ - even_msg
      odd_msg db 'Odd Number!'
      len2 equ $ - odd_msg
  
  section .bss
      num resb 5    ;Reserved 5 Bytes for Input
  
  section .text
  
  global _start     ;must be declared for linker (gcc)
  
  _start:
      ;User Prompt
      mov ebx, 1           ;file descriptor (stdout)
      mov ecx, userMsg     ;message to write 'Please enter a number'
      mov edx, lenuserMsg  ;message length
      mov eax, 4           ;system call number (sys_write)
      int 0x80             ;call kernel
  
      ;Taking user input
      mov ebx, 0           ;(stdin)
      mov ecx, num 
      mov edx, 5           ;i/p length
      mov eax, 3           ;system call number (sys_read)
      int 0x80             ;call kernel
  
      mov ax, [num]
      and ax, 1
      jz evnn              ;Jump on Even
  
      ;Printing No. is Odd
      mov ebx, 1           ;file descriptor (stdout) 
      mov ecx, odd_msg     ;message to write 'Odd Number!'
      mov edx, len2        ;message length
      mov eax, 4           ;system call number (sys_write)
      int 0x80             ;call kernel
      jmp outprog          ;Jump to exit
  
      ;Printing No. is Even
      evnn:
      mov ebx, 1           ;file descriptor (stdout) 
      mov ecx, even_msg    ;message to write 'Even Number!'
      mov edx, len1        ;message length  
      mov eax, 4           ;system call number (sys_write)
      int 0x80             ;call kernel
  
      ;Exit
      outprog: 
      mov eax, 1           ;system call number (sys_exit)
      int 0x80             ;call kernel
  </code></pre>