title: In NASM, I want to compare an input keystroke based on its ASCII value
body: <p>A simple program I am working on (for Homework) requires that I take a keystroke as input and return the categories it falls under (is it a printable charater, decimal, etc..)</p>
  
  <p>I'm using cmp to compare the keystroke against the values of the maximum and/or minimum values in it's category (for example if the ASCII code of the keystroke is above 0x7F then it is a printable character)</p>
  
  <p>However, there is obviously something not working in my comparison since no matter what, i.e. when I use the escape button as input, it is not printing "Control Key".</p>
  
  <p>Could it be that keys need some more processing before they can be compared based on ASCII value?</p>
  
  <p>Here is my code</p>
  
  <pre><code>  segment .data
      controlKey: db "Control Key", 10
      controlLen: equ $-controlKey
  
      printableKey: db "Printable", 10
      printableLen: equ $-printableKey
  
      decimalKey: db "Decimal", 10
      decimalLen: equ $-decimalKey
  
  segment .bss
  
      key resb 2
  
  segment .text
  
      global main
  main:
      mov eax, 3  ; system call 3 to get input
      mov ebx, 0  ; standart input device
      mov ecx, key    ; pointer to id
      mov edx, 2  ; take in this many bytes
      int 0x80    
  
  control:        ; check if it's a control key
      mov ebx, 31 ; highest control key
      mov edx, key
      cmp edx, ebx
      jg  printable
      mov eax, 4
      mov ebx, 1
      mov ecx, controlKey
      mov edx, controlLen
      int 0x80
      ; jmp exit  ; It's obviously not any of the other categories
  
  printable:  ; Tell that it's a printable symbol
      mov eax, 4
      mov ebx, 1
      mov ecx, printableKey
      mov edx, printableLen
      int 0x80
  decimal: 
      mov ebx, 30h    ; smallest decimal ASCII 
      mov edx, key
      cmp edx, ebx
      jl  uppercase
      mov ebx, 39h    ; test against 9
      cmp edx, ebx
      jg  uppercase
      mov eax, 4
      mov ebx, 1
      mov ecx, decimalKey
      mov edx, decimalLen
      int 0x80
  
  uppercase:  
  lowercase:
  
  
  
      mov eax, 4  ; system call 4 for output
      mov ebx, 1  ; standard output device
      mov ecx, key    ; move the content into ecx
      mov edx, 1  ; tell edx how many bytes
      int 0x80    ;
  
  exit:
      mov eax, 1
      xor ebx, ebx
      int 0x80
  </code></pre>