home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 6.ddi / TASMEXMP.ZIP / HEXMOD.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.6 KB  |  48 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; HEXMOD.ASM
  4.  
  5. ; From the Turbo Assembler Users Guide
  6.  
  7.         .MODEL large,PASCAL
  8.         .CODE
  9. HexStr  PROC FAR num:DWORD, byteCount:BYTE RETURNS result:DWORD
  10.         PUBLIC HexStr
  11.         les di,result     ;get address of function result
  12.         mov dx,ds          ;save Turbo's DS in DX
  13.         lds si,num         ;get number address
  14.         mov al,byteCount   ;how many bytes?
  15.         xor ah,ah          ;make a word
  16.         mov cx,ax          ;keep track of bytes in CX
  17.         add si,ax          ;start from MS byte of number
  18.         dec si
  19.         shl ax,1           ;how many digits? (2/byte)
  20.         cld                ;store # digits (going forward)
  21.         stosb              ;in destination string's length byte
  22. HexLoop:
  23.         std                ;scan number from MSB to LSB
  24.         lodsb              ;get next byte
  25.         mov ah,al          ;save it
  26.         shr al,1           ;extract high nibble
  27.         shr al,1
  28.         shr al,1
  29.         shr al,1
  30.         add al,90h         ;special hex conversion sequence
  31.         daa                ;using ADDs and DAA's
  32.         adc al,40h       
  33.         daa                ;nibble now converted to ASCII
  34.         cld                ;store ASCII going up
  35.         stosb
  36.         mov al,ah          ;repeat conversion for low nibble
  37.         and al,0Fh
  38.         add al,90h
  39.         daa
  40.         adc al,40h
  41.         daa
  42.         stosb
  43.         loop  HexLoop       ;keep going until done
  44.         mov  ds,dx          ;restore Turbo's DS
  45.         ret
  46. HexStr  ENDP
  47.         END
  48.