Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DATA SEGMENT
  2.     Buffer DB 7, '?', 6 dup('?'), '$'
  3.     Error DB 'Error$'
  4.     Message1 DB 'Enter number: $'
  5.     Message2 DB 'Press to show number..', 0Dh, 0Ah, '$'
  6. DATA ENDS
  7.  
  8. CODE SEGMENT
  9.     ASSUME CS:CODE, DS:DATA
  10.     Start:
  11.     mov ax,DATA
  12.     mov ds,ax
  13.    
  14.     mov dx,offset Message1
  15.     mov ah, 9
  16.     int 21h
  17.    
  18.     call Get_integer
  19.     cmp di,2
  20.     jz er
  21.    
  22.     push ax
  23.     mov dx,offset Message2
  24.     mov ah, 9
  25.     int 21h
  26.     mov ah, 10h
  27.     int 16h
  28.     pop ax
  29.    
  30.     call Print_integer
  31.     mov ah, 4Ch
  32.     int 21h
  33.    
  34.     er:
  35.     mov dx, offset Error
  36.     mov ah,09
  37.     int 21h
  38.     mov ah, 4Ch
  39.     int 21h
  40.  
  41. Get_integer proc
  42.  
  43.     mov ah,0ah
  44.     xor di,di
  45.     mov dx,offset Buffer
  46.     int 21h
  47.     mov dl,0ah
  48.     mov ah,02
  49.     int 21h
  50.  
  51.     mov si,offset Buffer+2
  52.     cmp byte ptr [si],"+"
  53.     jz p1
  54.     cmp byte ptr [si],"-"
  55.     jnz p2
  56.     mov di,1
  57.     p1:  
  58.     inc si    
  59.     p2:
  60.     xor ax,ax
  61.     mov bx,10  
  62.     p3:
  63.     mov cl,[si]
  64.     cmp cl,0dh  
  65.     jz endin
  66.    
  67.  
  68.     cmp cl,'0'  
  69.     jb erg
  70.     cmp cl,'9'
  71.     ja erg
  72.  
  73.     sub cl,'0'
  74.     mul bx    
  75.     add ax,cx
  76.     jc erg
  77.     cmp ax, 8000h
  78.     ja erg
  79.     inc si    
  80.     jmp p3  
  81.  
  82.     erg:  
  83.     mov di,2
  84.     ret
  85.  
  86.     endin:
  87.     cmp di,1
  88.     jnz p4
  89.     neg ax
  90.     p4:
  91.     ret
  92. Get_integer endp
  93.  
  94. Print_integer proc
  95.  
  96.     mov bx, ax
  97.     or bx, bx
  98.     jns ml
  99.     mov al, '-'
  100.     int 29h
  101.     neg bx
  102.     ml:
  103.     mov ax,bx
  104.     xor cx,cx
  105.     mov bx,10
  106.     m2:
  107.     xor dx,dx
  108.     div bx
  109.     add dl,'0'
  110.     push dx
  111.     inc cx
  112.     test ax,ax
  113.     jnz m2
  114.     m3:
  115.     pop ax
  116.     int 29h
  117.     loop m3
  118.     ret
  119.  
  120. Print_integer endp
  121.  
  122. CODE ENDS
  123. END Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement