title: How to calculate average? (masm x86 8086)
body: <p>I am trying to find the average of two user inputted numbers on MASM x86 (im using 8086). I cannot seem to calculate the average!! I can get the two numbers to multiply but I do not have a clue on how to add them and then divide them by the total amount of numbers(which in my case it is only 2).  Here is what i have so far(and yes i realize that i am multiplying, but that is to only show that I did attempt something, I just cant get them to add and divide the sum):</p>
  
  <pre><code>.model small
  org 100h
  .data
  
  num1 db ?
  num2 db ?
  result db ? 
  usermsg db "Enter EVEN numbers only.$"
  msg1 db 13, 10, "Enter first number: $"
  msg2 db 13, 10, "Enter second number: $"
  msg3 db 13, 10, "The average is: $"
  
  .code
  
  main proc
  mov ax, @data
  mov ds, ax
  
  lea dx, usermsg
  mov ah, 09h
  int 21h
  
  lea dx, msg1
  mov ah, 09h
  int 21h
  
  mov ah, 01h
  int 21h
  
  sub al, '0'
  mov num1, al 
  mov dl, al
  
  lea dx, msg2
  mov ah, 09h
  int 21h
  
  mov ah, 01h
  int 21h
  sub al, '0'
  mov num2, al
  
  mul num1
  
  
  ;add al, num1
  
  mov result, al
  
  
  idiv result, 2 ;new code
  aam
  
  add ah, '0'
  add al, '0'
  mov bx, ax
  
  lea dx, msg3
  mov ah, 09h
  int 21h
  
  mov ah, 02h
  mov dl, bh
  int 21h
  mov dl, bl
  int 21h
  
  mov ax, 4c00h
  int 21h
  </code></pre>