home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / math / asc16.asm < prev    next >
Assembly Source File  |  1986-01-17  |  2KB  |  32 lines

  1. ASC16    PROC     NEAR
  2. ;***************************************************************
  3. ;                    Converts a 16-bit signed integer to ASCII
  4. ;                    SI offset to integer; DI to last byte of 
  5. ;                    ASCII location. BX returns offset to first
  6. ;                    character (sign) of ASCII value
  7. ;***************************************************************
  8.          PUSH     SI
  9.          SUB      AX,AX           ;clear AX
  10.          OR       AX,[SI]         ;get binary integer
  11. ;                            check sign
  12.          MOV      SI," "          ;assume sign positive
  13.          JNS      ASC16A
  14.          MOV      SI,"-"          ;save negative sign
  15.          NEG      AX              ;and make integer positive
  16. ;                            convert to ASCII decimal
  17. ASC16A:  MOV      BX,DI           ;initial offset in BX
  18.          MOV      CX,10           ;decimal 10 in CX
  19. ASC16B:  SUB      DX,DX           ;clear DX
  20.          DIV      CX              ;divide by 10
  21.          ADD      DX,48           ;convert remainder to ASCII
  22.          MOV      [BX],DL         ;save it
  23.          DEC      BX              ;point to next position
  24.          OR       AX,AX           ;if quotient is not zero
  25.          JNZ      ASC16B          ;do it again
  26. ;                            set sign
  27.          MOV      AX,SI           ;sign in AL
  28.          MOV      [BX],AL         ;save it
  29. ;                              
  30.          POP      SI
  31.          RET
  32. ASC16    ENDP