xFunKy

getNum

Jun 2nd, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getNum proc
  2.     push ax
  3.     push bx
  4.     push cx
  5.     push dx
  6.     mov cl, 0 ;How many digits
  7.     mov bx, 0 ;Holds the number
  8.     nextDigit:
  9.     mov ah, 1 ;Get char
  10.     int 21h
  11.     cmp al, 13 ;If enter end
  12.     je return
  13.     sub al, 48
  14.     jc noDigit
  15.     cmp al, 9
  16.     jbe yesDigit
  17.     noDigit:
  18.         call delete
  19.         jmp nextDigit        
  20.     yesDigit:
  21.         inc cl
  22.         mov dx, 10
  23.         mov ah, 0
  24.         push ax ;Save ax
  25.         mov ax, bx
  26.         mul dx
  27.         mov bx, ax
  28.         pop ax
  29.         add bx, ax      
  30.         cmp cl, 4
  31.         jne nextDigit
  32.     return:
  33.     mov answer, bx
  34.     pop dx
  35.     pop cx    
  36.     pop bx
  37.     pop ax
  38.     ret
  39. getNum endp
  40.  
  41. delete proc
  42.     push ax
  43.     push dx
  44.     mov ah, 2
  45.     mov dl, 08h ;Backspace
  46.     int 21h
  47.     mov ah, 2
  48.     mov dl, 00h ;null
  49.     int 21h
  50.     mov ah, 2
  51.     mov dl, 08h ;Backspace
  52.     int 21h    
  53.     pop dx
  54.     pop ax
  55.     ret
  56. delete endp
Advertisement
Add Comment
Please, Sign In to add comment