home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / tools / debugger / mdebug / mdebug1 / konvert.a86 < prev    next >
Encoding:
Text File  |  1992-06-04  |  2.7 KB  |  129 lines

  1.  
  2. ; ----------------------------
  3. ; KONVERT
  4. ;
  5. ; Enthält: Assembler-Routinen zur Konvertierung von Werten in Hexstrings
  6. ;
  7. ; Besonderheiten: Alle Routinen sind als FAR-Routinen kodiert
  8. ;
  9. ; Übersetzen:     A86 KONVERT.A86 to KONVERT.OBJ
  10. ;
  11. ; ----------------------------
  12.  
  13. CODE SEGMENT BYTE PUBLIC
  14.      ASSUME CS:CODE
  15.  
  16. ; ----------------------------
  17.  
  18. PUBLIC HexByte
  19.  
  20. PUBLIC HexWord
  21.  
  22. ; ----------------------------
  23. ; HexByte
  24. ;
  25. ; Funktion:           Umwandeln eines Bytes in einen HexString
  26. ;
  27. ; Pascal-Deklaration: {$F+} FUNCTION HexByte(zahlb : BYTE):STRING; EXTERNAL; {$F-}
  28. ;
  29. ; Eingabe-Parameter:  zahlb - Umzuwandelndes Byte
  30. ;
  31. ; Ausgabe-Parameter:  Als Funktions-Wert wird der HexString zurueckgegeben
  32. ;
  33. ; Besonderheiten:     Der Funktionswert ist immer 2 Zeichen lang
  34. ;
  35.  
  36. zahlb EQU [BP+06h]            ; Offsets der Parameter auf dem Stack
  37. str2  EQU [BP+08h]
  38.  
  39. HexByte PROC FAR
  40.          push bp
  41.          mov bp,sp
  42.          cld
  43.          les di,str2
  44.          mov b es:[di],02h
  45.          inc di
  46.  
  47.          mov al,zahlb
  48.          call Konvert_AL_TO_AX
  49.          stosw
  50.  
  51.          pop bp
  52.          retf 2               ; Parameter vom Stack und raus
  53.  
  54. ; ----------------------------
  55. ; HexWord
  56. ;
  57. ; Funktion:           Umwandeln eines Wortes in einen HexString
  58. ;
  59. ; Pascal-Deklaration: {F+} FUNCTION HexWord(zahlw : WORT):STRING; EXTERNAL; {$F-}
  60. ;            
  61. ; Eingabe-Paramter:   zahlw - umzuwandelndes Wort
  62. ;
  63. ; Augabe-Paramter:    Als Funktions-Wert wird der HexString zurueckgegeben
  64. ;
  65. ; Besonderheiten:     Der Funktionswert ist immer 4 Zeichen lang
  66. ;
  67.  
  68. zahlw EQU [BP+06]             ; Offsets der Parameter auf dem Stack
  69. str4  EQU [BP+08]
  70.  
  71. HexWord PROC FAR
  72.          push bp
  73.          mov bp,sp
  74.          cld
  75.          les di,str4
  76.          mov b es:[di],4
  77.          inc di
  78.  
  79.          mov ax,zahlw
  80.          push ax
  81.          mov al,ah
  82.          call Konvert_AL_TO_AX
  83.          stosw
  84.          pop ax
  85.          call Konvert_AL_TO_AX
  86.          stosw
  87.  
  88.          pop bp
  89.          retf 2               ; Parameter vom Stack und raus
  90.  
  91. ; ---------------------------
  92. ; Konvert_AL_To_AX
  93. ;
  94. ; Funktion: Konvertiert AL in einen Hexstring
  95. ;
  96. ; Eingabe:  AL = zu konvertierender Wert
  97. ;
  98. ; Ausgabe:  AL = oberes Nibble als Hexziffer
  99. ;           AH = unteres Nibble als Hexziffer
  100. ;
  101. Konvert_AL_TO_AX PROC NEAR
  102.          mov ah,al
  103.          and ah,0F0h
  104.          shr ah,1
  105.          shr ah,1
  106.          shr ah,1
  107.          shr ah,1
  108.          cmp ah,9xD
  109.          jg >l1
  110.          add ah,48xD
  111.          jmp >l2
  112. l1:
  113.          add ah,55xD
  114. l2:
  115.          and al,00Fh
  116.          cmp al,9xD
  117.          jg >l1
  118.          add al,48xD
  119.          jmp >l2
  120. l1:
  121.          add al,55xD
  122. l2:
  123.          xchg ah,al
  124.          ret
  125.  
  126.          CODE ENDS
  127. ; ----------------------------
  128.  
  129.