title: x86 assembly multiply and divide instruction operands, 16-bit and higher
body: <p>I'm rather confused about how the multiply and divide operations work in x86 assembly. For example, the code below doesn't seem too difficult since deals with 8-bit.</p>
  
  <p>8-Bit Multiplication:</p>
  
  <pre><code>; User Input:
  ; [num1], 20
  ; [num2] , 15
  
  mov    ax, [num1]    ; moves the 8 bits into AL
  mov    bx, [num2]    ; moves the 8 bits into BL
  
  mul    bl            ; product stored in AX
  
  print  ax
  </code></pre>
  
  <p>But what happens when you want to multiply two 16-bit numbers? How would one multiply two 16 bit numbers the same way as it has been done with the 8 bit numbers?</p>
  
  <p>I'm confused as to what registers the values would be stored in. Would they be stored in AL and AH or would it simply store the 16-bit number in AX. To show what I mean:</p>
  
  <pre><code>; User Input:
  ; [num1], 20
  ; [num2], 15
  
  mov    eax, [num1]    ; Does this store the 16-bit number in AL and AH or just in AX
  mov    ebx, [num2]    ; Does this store the 16-bit number in BL and BH or just in BX
  
  mul    ???            ; this register relies on where the 16-bit numbers are stored
  
  print  eax
  </code></pre>
  
  <p>Could someone elaborate a bit on how the multiplying and dividing works? (specifically with 16-bit and 32-bit numbers? Would I need to rotate bits if the values are stored in the lower AL and AH?</p>
  
  <p>Or can one simply <code>mov num1</code> and <code>num2</code> into <code>ax</code> and <code>bx</code> respectively and then multiply them to get the product in <code>eax</code>?</p>