home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / ITOA.ZIP / TRYITOA.ASM < prev   
Encoding:
Assembly Source File  |  1987-12-15  |  2.7 KB  |  105 lines

  1.         name    tryitoa
  2.         title   TRYITOA
  3.         page    55,132
  4.  
  5. ;
  6. ; TRYITOA.ASM --- a simple demonstration of
  7. ;                 the ITOA and ATOI routines.
  8. ;
  9. ; Ray Duncan, October 1987
  10. ;
  11.  
  12. cr      equ     0dh
  13. lf      equ     0ah
  14.  
  15.  
  16. DGROUP  group   _DATA
  17.  
  18.  
  19. _TEXT   segment word public 'CODE'
  20.  
  21.         assume  cs:_TEXT,ds:_DATA
  22.  
  23.         extrn   itoa:near
  24.         extrn   atoi:near
  25.  
  26. main    proc    near
  27.  
  28.         mov     ax,_DATA                ; make our data segment
  29.         mov     ds,ax                   ; addressable...
  30.         mov     es,ax
  31.         
  32. main1:  mov     dx,offset prompt        ; display a prompt
  33.         mov     cx,p_len                ; to the user...
  34.         mov     bx,1                    ; "Enter value: " 
  35.         mov     ah,40h
  36.         int     21h
  37.         jc      main2                   ; if error, just exit
  38.  
  39.         mov     dx,offset inbuff        ; read keyboard entry
  40.         mov     cx,80                   ; from the user...
  41.         mov     bx,0
  42.         mov     ah,3fh
  43.         int     21h
  44.         jc      main2                   ; if error, just exit
  45.  
  46.         cmp     ax,2                    ; did he enter anything?
  47.         je      main2                   ; empty line, exit
  48.  
  49.         mov     dx,offset display       ; display "You entered: "
  50.         mov     cx,d_len                ; to the user...
  51.         mov     bx,1
  52.         mov     ah,40h
  53.         int     21h
  54.         jc      main2                   ; if error, just exit
  55.         
  56.         mov     si,offset inbuff        ; convert convert user's 
  57.         call    atoi                    ; input to binary in AX
  58.                                         
  59.         mov     cx,10                   ; convert value in AX back 
  60.         mov     si,offset outbuff       ; to ASCII string for output
  61.         call    itoa
  62.  
  63.         mov     cx,ax                   ; CX = string length
  64.         mov     dx,si                   ; DS:DX = string address 
  65.         mov     bx,1                    ; now display converted
  66.         mov     ah,40h                  ; ASCII string...
  67.         int     21h                     ; 
  68.         jc      main2                   ; if error, just exit
  69.  
  70.         jmp     main1                   ; do it again...
  71.  
  72.  
  73. main2:  mov     ax,4c00h                ; final exit to MS-DOS
  74.         int     21h
  75.  
  76. main    endp
  77.  
  78. _TEXT   ends
  79.  
  80.  
  81. _DATA   segment word public 'DATA'
  82.  
  83. prompt  db      cr,lf,lf,'Enter a number: '
  84. p_len   equ     $-prompt
  85.  
  86. display db      cr,lf,lf,'You entered:',4 dup(32)
  87. d_len   equ     $-display
  88.  
  89. inbuff  db      80 dup (?)
  90.  
  91. outbuff db      80 dup (?)
  92.  
  93. _DATA   ends
  94.  
  95.  
  96.  
  97. STACK   segment para stack 'STACK'
  98.         
  99.         db      128 dup (?)
  100.  
  101. STACK   ends
  102.  
  103.  
  104.         end     main
  105.