home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CEXPRESS.ZIP / BITS.ASM / BIN2CHAR.ASM next >
Assembly Source File  |  1989-05-03  |  2KB  |  58 lines

  1. ;unsigned char  binary_to_char(binary_string);
  2. ;  unsigned char  *binary_string;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _binary_to_char
  10. _binary_to_char proc near
  11.     mov  _error_code,1    ;1 = error
  12.     mov  bx,sp        ;BX pts to stack
  13.     pushf            ;
  14.     push di            ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bx            ;else add 2 to BX
  19.     inc  bx            ;
  20. begin:    cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;jump if near
  22.     les  di,ss:dword ptr[bx+2] ;ES:DI pts to BinaryString
  23.     jmp  short L00        ;jump ahead
  24. L0:    mov  ax,ds        ;ES = DS
  25.     mov  es,ax        ;
  26.     mov  di,ss:[bx+2]    ;
  27. L00:    sub  ax,ax        ;clear AX
  28.     mov  si,di        ;copy to SI
  29.     mov  bx,1        ;bit mask at bottom of BX
  30.     cmp  byte ptr es:[di],0 ;null string?
  31.     je   L3            ;quit if null
  32.     mov  cx,9        ;must find end of string
  33.     mov  al,0        ;
  34.     cld            ;
  35.     repne scasb        ;go scan for terminating zero
  36.     jnz  L3            ;quit if string over 8 chars
  37.     dec  di            ;ptr to terminating 0
  38.     mov  cx,di        ;calculate number chars in string
  39.     sub  cx,si        ;
  40.     dec  di            ;ptr to last char of string
  41.     dec  _error_code    ;0 = no error
  42. L1:    cmp  byte ptr es:[di],'1' ;is the char a '1'?
  43.     jne  L2            ;if not, jump ahead
  44.     or   ax,bx        ;set corresponding bit
  45. L2:    shl  bx,1        ;shift mask to next bit
  46.     dec  di            ;pt to next byte of strg
  47.     loop L1            ;go do the next byte
  48. L3:    pop  si            ;
  49.     pop  di            ;
  50.     popf            ;
  51.     cmp  _memory_model,0    ;quit
  52.     jle  quit        ;
  53.     db   0CBh        ;RET far
  54. quit:    ret            ;RET near
  55. _binary_to_char ENDP
  56. _TEXT    ENDS
  57.     END
  58.