title: Displaying an ASCII character as digits in 16-bit assembly
body: <p>I'm trying to write a program to get a sum of 3 values and getting the mean. So far, I was able to get the sum &quot;correctly&quot; by subtracting a certain value from the sum to get the leading digit of the sum. Subtracting 27h/29 from the sum may not be the most effective method. I know that this may not be the optimal solution, but using division gives me some errors and displays some random symbols as seen on the block I turned into comments.</p>
  <pre><code>TITLE Add       (sum.asm)
  
  ; This program adds 8-bit values
  
  .model small
  .stack 100h
  .data
  ThreeBytes db 10h, 20h, 30h   ;expected sum is 60h or 96d
  message db 0ah, 0dh,&quot;Sum = &quot;
  TheSum db ?, 0ah, 0dh, &quot;$&quot;
  
  
  .code
  main PROC
     mov  ax, @data
     mov  ds, ax
     mov  al, ThreeBytes
     add  al, ThreeBytes + 1
     add  al, ThreeBytes + 2
     ;sub al, 40  
     
     ; mov ch, 0
     ; mov ch, al
     ; mov bl, 10
     ; div bl
     
     sub al, 27h ;or 39d to get 9
     mov  TheSum, al ;output is ' (apostrophe) = 60h or 96d
  
     mov  dx, offset message
     mov  ah, 9
  
     
     int 21h
     mov ax, 4C00h
     int 21h
  
  main endp
  end main
  </code></pre>
  <p>Here is the output that I'm getting from DOSBox: <a href="https://i.stack.imgur.com/SCg1a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SCg1a.png" alt="enter image description here" /></a></p>
  <p>I am a complete beginner with little to no knowledge of assembly language, so I'm hoping for a simple solution/explanation. The code above is a combination of different programs I found, and it does kinda work.</p>