home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / CONV05.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  2KB  |  77 lines

  1.     page    66,132
  2. ;******************************** CONV05.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  14. HEX_STR_TO_BYTE - convert 2 hex ascii characters to 1 hex byte
  15. ;
  16. ;  inputs: ds:si points at hex data
  17. ;  
  18. ;  output: no carry - al = hex byte
  19. ;             carry - bad input data
  20. ;* * * * * * * * * * * * * *
  21. 
  22. ;----------------------------------------------------------------------------
  23.     public    HEX_STR_TO_BYTE
  24. HEX_STR_TO_BYTE    PROC    FAR
  25.     push    cx
  26.     mov    ch,0
  27.     call    hex_nibble
  28.     jc    at1_exit    ;jmp if conversion error
  29.     call    hex_nibble
  30.     mov    al,ch
  31. at1_exit:
  32.     pop    cx
  33.     retf
  34. HEX_STR_TO_BYTE    ENDP    
  35. ;---------------------------    
  36. hex_nibble:
  37.     lodsb
  38.     mov    cl,4
  39.     cmp    al,'a'
  40.     jb    hn_ok1
  41.     sub    al,20h        ;convert to upper case if alpha
  42. hn_ok1:    sub    al,'0'        ;check if legal
  43.     jc    hn_abort    ;jmp if out of range
  44.     cmp    al,9
  45.     jle    hn_got        ;jmp if number is 0-9
  46.     sub    al,7        ;convert to number from A-F or 10-15
  47.     cmp    al,15        ;check if legal
  48.     ja    hn_abort    ;jmp if illegal hex char
  49. hn_got:    shl    ch,cl
  50.     or    ch,al
  51.     clc
  52.     jmp    hn_exit
  53. hn_abort:
  54.     stc
  55. hn_exit:        
  56.     ret    
  57. comment 
  58. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  59. HEX_STR_TO_WORD - convert 4 hex ascii characters to 2 hex bytes
  60. ;
  61. ;  inputs: ds:si points at hex data
  62. ;  
  63. ;  output: no carry - al = hex word
  64. ;             carry - bad input data
  65. ;* * * * * * * * * * * * * *
  66. 
  67.     public    HEX_STR_TO_WORD
  68. HEX_STR_TO_WORD    PROC    FAR
  69.     call    HEX_STR_TO_BYTE
  70.     mov    ah,al
  71.     call    HEX_STR_TO_BYTE
  72.     retf
  73. HEX_STR_TO_WORD    ENDP    
  74.  
  75. LIBSEG    ENDS
  76.     end
  77.