home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / chapxmpl.arc / HEXSTR2.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-10-09  |  1.1 KB  |  43 lines

  1.         .MODEL    TPASCAL
  2.         .CODE
  3. HexStr    PROC    FAR NUM:DWORD,AnzahlBytes:BYTE RETURNS ErgebnisPtr:DWORD
  4.         PUBLIC    HexStr
  5.         les    di,ErgebnisPtr        ; Adresse des Ergebnisses
  6.         mov    dx,ds            ; DS von Turbo in DX speichern
  7.         lds    si,Num            ; Adresse der Zahl
  8.         mov    al,AnzahlBytes        ; Wieviele Bytes?
  9.         xor    ah,ah            ; Umwandlung in Wort
  10.         mov    cx,ax            ; Anzahl der Bytes in CX
  11.         add    si,ax            ; Beim höchsten Byte anfangen
  12.         dec    si                ; Zeiger zurücksetzen
  13.         shl    ax,1                ; Wieviel Ziffer? (2 pro Byte)
  14.         cld                    ; Anzahl der Bytes in
  15.         stosb                ; im String speichern
  16. HexSchleife:
  17.         std                    ; Von vorn nach hinten
  18.         lodsb                ; Nächstes Byte
  19.         mov    ah,al            ; Zwischenspeichern
  20.         shr    al,1                ; Oberstes Nibble isolieren
  21.         shr    al,1
  22.         shr    al,1
  23.         shr    al,1
  24.         add    al,90h            ; Hex-Umwandlung mit
  25.         daa                    ; ADD und DAA
  26.         adc    al,40h
  27.         daa                    ; Nibble umgewandelt
  28.         cld
  29.         stosb                ; ASCII-Zeichen speichern
  30.         mov    al,ah            ; Anderes Nibble umwandeln
  31.         and    al,0Fh
  32.         add    al,90h
  33.         daa
  34.         adc    al,40h
  35.         daa
  36.         stosb
  37.         loop    HexSchleife        ; weitermachen
  38.         mov    ds,dx            ; DS von Turbo wieder herstellen
  39.         ret                    ; Parameter mit 6 Bytes
  40. HexStr    ENDP
  41. CODE        ENDS
  42.         END
  43.