title: How does 'cmp' command works?
body: <p>I have assembly class at my university and having trouble understanding some of the basic operations (i'v missed couple of classes in the beginning).</p>
  
  <p>I have a simple program that prints a number, this is the program:</p>
  
  <pre><code>.model  small
  .stack   100h
  .data
  
  num  dw  -32768
  numS db  6 dup(' '),'$'
  
  .code
      mov ax, @data
      mov ds, ax
  
      mov ax, num
      mov bx, 10
  
      mov si, offset numS+5
  
  next:
      cwd
      idiv    bx
      cmp dx, 0
      jge cont
      neg dx
  
  cont:
      add dl, 48
      mov [si],   dl
      dec si
      cmp ax, 0
      jz  sof
      jmp next
  
  sof:    
      cmp num,    0
      jge soff
      mov byte ptr[si],   '-'
  
  soff:
      mov ah, 9
      mov dx, si
      int 21h
      .exit
  
  end
  </code></pre>
  
  <p>I checked in other website what is the cmp command is doing and the actual algo is opr1 - opr2...so in this program i take the reminder of the devision (ax/bx which placed in dx) and decrement zero from it..? I dont understand how is the comparison works here.. :/</p>
  
  <p>Please help me understand it, im a complete beginner here and im stuck..</p>
  
  <p>If someone doesn't mind to explain this program in general and give extra focus to the comparison that would be awesome..</p>
  
  <p>cheers  </p>