home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / STRTUP10.ZIP / STARTUP.ZIP / LIBSRC / UTOA.ASM < prev   
Encoding:
Assembly Source File  |  1997-02-28  |  3.6 KB  |  150 lines

  1.     page 60, 132
  2.     title    UTOA - Unsigned Integer to ASCIIZ
  3.     name    UTOA
  4. comment ÷
  5.     UTOA                            V1.00
  6. ==========================================================================
  7. NAME
  8.     UTOA - Unsigned Integer to ASCIIZ
  9.  
  10. SYNOPSIS
  11.     mov    ax, seg TargetString    ; If large data model
  12.     mov    es, ax
  13.     mov    di, TargetString
  14.     mov    ax, SourceInteger
  15.     call    UTOA
  16.  
  17. DESCRIPTION
  18.     This procedure converts a binary unsigned integer into an ASCIIZ
  19.     string.
  20.  
  21.     The unsigned integer to be converted is passed in the AX register.
  22.     The ES:DI register pair must point to the destination string which
  23.     is overwritten by the result.  The destination string must be at
  24.     least six characters in length.
  25.  
  26. CAUTION
  27.     If the destination string is not at least six characters in length,
  28.     UTOA may write beyond the end of the string.  No checking is done
  29.     within UTOA.
  30.  
  31. RETURNS
  32.     Nothing
  33.  
  34. PROGRAMMING NOTES
  35.     Assembled with Microsoft MASM V6.11a
  36.  
  37.     Use MEMMOD to specify the memory model.
  38.     /dMEMMOD=TINY|SMALL|COMPACT|MEDIUM|LARGE|HUGE
  39.  
  40. REGISTER USAGE
  41.     Small Data Memory Models:
  42.     AX, BX, CX and DX are used.
  43.  
  44. MEMORY UTILIZATION
  45.     DATA
  46.         None
  47.  
  48.     CODE
  49.                     8086    80286+
  50.         Small Code Model:         47
  51.         Large Code Model:         47
  52.  
  53.     STACK
  54.         Small Code Model:         10
  55.         Large Code Model:         12
  56.  
  57. EXTERNAL LIBRARIES
  58.     None
  59.     
  60. EXTERNAL PROCEDURES
  61.     None
  62.  
  63. INTERUPTS CALLED
  64.     None
  65.  
  66. GLOBAL NAMES
  67.     UTOA - Procedure Name
  68.  
  69. AUTHOR
  70.     Raymond Moon - 6 Oct 95
  71.  
  72.     Copyright (c) 1995 - Raymond Moon
  73.     ALL RIGHTS RESERVED
  74.  
  75. HISTORY
  76.     Version    - Date        - Remarks
  77.     1.00    -  6 Oct 95    - Orginal
  78. ==========================================================================
  79.     ÷ Commend End
  80.  
  81. ;----------------------------
  82. ;    Make the small memory model the default.
  83.  
  84. ifndef    memmod
  85. memmod    equ    <small>
  86. endif
  87.  
  88. ;----------------------------
  89. ;    Specify processor, memory model, language and ES register assume. 
  90.  
  91.     include procesor.inc            ; Specify target processor
  92. %    .model memmod, fortran
  93.     assume es:DGROUP
  94.  
  95. ;=========================================================================
  96. ;    CODE
  97. ;=========================================================================
  98. ;    Start Code Segment, define UTOA procedure, and declare local TEMP
  99. ;    variable for storage on intermediate result.
  100.  
  101.     .CODE
  102.  
  103. UTOA    proc
  104. local    TEMP[6]:byte            ; Create temp storage for result
  105.  
  106. ;----------------------------
  107. ;    Set up CX as the divisor.  Converting to base 10 so CX = 10.
  108. ;    Set up temporary storage for intermediary result; BX => TEMP.
  109. ;    Load null terminator into TEMP.  Clear DX as DX:AX is the dividend.
  110.  
  111.     mov    cx, 10            ; BX = 10 -- the divisor
  112.     xor    dx, dx            ; Clear upper bits
  113.     lea    bx, TEMP        ; BX => TEMP
  114.     mov    [bx], dl        ; Add null terminator
  115.     inc    bx            ; Account for null
  116.  
  117. ;----------------------------
  118. ;    AX = value to convert.    Loop through by dividing by 10, converting
  119. ;    the remainder to ASCII and saving until the quotient is zero.
  120.  
  121. UA1:    div    cx            ; AX = Quotient/DX = remainder
  122.     or    dl, 30h            ; Convert to ASCII
  123.     mov    [bx], dl        ; Store it
  124.     inc    bx            ; BX => next char
  125.     xor    dx, dx            ; Null upper bytes
  126.     or    ax, ax            ; Is the Quotient == 0?
  127.     jnz    UA1            ; No, continue
  128.  
  129. ;----------------------------
  130. ;    The integer has been converted but is in reverse order in TEMP.
  131. ;    Now, rewrite it in the proper order in the destination.  CX is
  132. ;    number of chars to copy - Remember the terminating null must be
  133. ;    copied also.
  134.  
  135.     mov    cx, bx            ; CX => last char + 1
  136.     lea    ax, TEMP        ; AX => first char
  137.     sub    cx, ax            ; CX => string length + null
  138.     dec    bx            ; BX => last char
  139. UA2:    mov    al, [bx]        ; AL = char
  140.     dec    bx            ; BX => next char
  141.     stosb                ; Store it
  142.     loop    UA2
  143.  
  144. ;----------------------------
  145. ;    Return
  146.  
  147.     ret
  148. UTOA    endp
  149.     end
  150.