title: DOS assembly read two succeeding characters, and convert to number
body: <p>I'm writing a simple program that takes in two numbers between 1-99, adds them and prints out the result. I'm done with the printing part, I can print up too three digits, 99+99=198 so it's enough for this program. I have the program working for two one digit numbers. </p>
  
  <p>Example: 
  1 1 =
  2 ,
  4 4 =
  8 </p>
  
  <p>So the digits is separated by spaces. Now I need the following; 
  11 1 =
  12,
  1 45 =
  46</p>
  
  <p>what I got so far, when I first read a valid number i store it on the stack while I check what the next char is, if the next is space then this number is only one-digit. If I have another character I have to multiply the first by 10 and then add the latest character. </p>
  
  <p>22 would be read like this: 2 2*10 = 20+2 = 22 </p>
  
  <p>Note that the rest of my program needs the result from this to be in register dl. 
  Got one tiny question about registers and assembly, can a number stored in dl be referenced with dx? I'm wondering because mov and arithmetic operators seems to demand that the registers(operands) are of the same size. </p>
  
  <p>My code so far</p>
  
  <pre><code>ReadNumber: ;; Reads one number 1-99
  push ax
  push bx
  push cx
  Lokke:
  ;; reads from keyboard
  mov ah,01h
  int 21h
  cmp al, " "
  je Lokke
  cmp al,"0"
  jb PrintError
  cmp al,"9"
  ja PrintError
  ;; First character is a valid number
  push ax
  ;;storing the first on the stack while checking the next character
  mov ah,01h
  int 21h
  cmp al," " 
  je OneNumber
  ;;This part runs if the next char is a valid digit.
  mov cl, al ;cl next digit
  pop ax ; getting back the first from the stack
  sub ax,"0" THIS LINE IS ADDED THANKS!!!!
  mov bl, 10 
  mul bl 
  add ax, cx
  mov dx,ax
  mov dh,0 ;success variable set to true
  mov dl,al
  sub dl,"0"
  pop ax
  pop bx
  pop cx
  ret
  OneNumber: 
  pop ax ;; Don't need it.
  mov dh,0 ;success variable set too true
  mov dl,al
  sub dl,"0"
  pop ax
  pop bx
  pop cx
  ret
  </code></pre>
  
  <p>This does not work properly, not even for one-digit numbers, I can't understand why :( 
  It looks just fine! Thanks for input :) </p>