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

  1. CODE        SEGMENT
  2.         ASSUME    CS:CODE, DS:NOTHING
  3.  
  4. ; Parameter (+2 wegen push bp)
  5.  
  6. AnzahlBytes    EQU    BYTE PTR SS:[BP+6]
  7. Num        EQU    DWORD PTR SS:[BP+8]
  8.  
  9. ; Adresse des Funktionsergebnisses (+2 wegen push bp)
  10.  
  11. ErgebnisPtr    EQU    DWORD PTR SS:[BP+12]
  12.  
  13. HexStr    PROC    FAR
  14.         PUBLIC    HexStr
  15.  
  16.         push    bp
  17.         mov    bp,sp                 ; Zeiger auf Stack
  18.         les    di,ErgebnisPtr        ; Adresse des Ergebnisses
  19.         mov    dx,ds            ; DS von Turbo in DX speichern
  20.         lds    si,Num            ; Adresse der Zahl
  21.         mov    al,AnzahlBytes        ; Wieviele Bytes?
  22.         xor    ah,ah            ; Umwandlung in Wort
  23.         mov    cx,ax            ; Anzahl der Bytes in CX
  24.         add    si,ax            ; Beim höchsten Byte anfangen
  25.         dec    si            
  26.         shl    ax,1                ; Wieviel Ziffer? (2 pro Byte)
  27.         cld                    ; Anzahl der Bytes in
  28.         stosb                ; im String speichern
  29. HexSchleife:
  30.         std                    ; Von vorn nach hinten
  31.         lodsb                ; Nächstes Byte
  32.         mov    ah,al            ; Zwischenspeichern
  33.         shr    al,1                ; Oberstes Nibble isolieren
  34.         shr    al,1
  35.         shr    al,1
  36.         shr    al,1
  37.         add    al,90h            ; Hex-Umwandlung mit
  38.         daa                    ; ADD und DAA
  39.         adc    al,40h
  40.         daa                    ; Nibble umgewandelt
  41.         cld
  42.         stosb                ; ASCII-Zeichen speichern
  43.         mov    al,ah            ; Anderes Nibble umwandeln
  44.         and    al,0Fh
  45.         add    al,90h
  46.         daa
  47.         adc    al,40h
  48.         daa
  49.         stosb
  50.         loop    HexSchleife        ; weitermachen
  51.         mov    ds,dx            ; DS von Turbo wieder herstellen
  52.         pop    bp
  53.         ret    6                ; Parameter mit 6 Bytes
  54.  
  55. HexStr    ENDP
  56. CODE        ENDS
  57.         END
  58.