home *** CD-ROM | disk | FTP | other *** search
- ;unsigned char binary_to_char(binary_string);
- ; unsigned char *binary_string;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _binary_to_char
- _binary_to_char proc near
- mov _error_code,1 ;1 = error
- mov bx,sp ;BX pts to stack
- pushf ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bx ;else add 2 to BX
- inc bx ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,ss:dword ptr[bx+2] ;ES:DI pts to BinaryString
- jmp short L00 ;jump ahead
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,ss:[bx+2] ;
- L00: sub ax,ax ;clear AX
- mov si,di ;copy to SI
- mov bx,1 ;bit mask at bottom of BX
- cmp byte ptr es:[di],0 ;null string?
- je L3 ;quit if null
- mov cx,9 ;must find end of string
- mov al,0 ;
- cld ;
- repne scasb ;go scan for terminating zero
- jnz L3 ;quit if string over 8 chars
- dec di ;ptr to terminating 0
- mov cx,di ;calculate number chars in string
- sub cx,si ;
- dec di ;ptr to last char of string
- dec _error_code ;0 = no error
- L1: cmp byte ptr es:[di],'1' ;is the char a '1'?
- jne L2 ;if not, jump ahead
- or ax,bx ;set corresponding bit
- L2: shl bx,1 ;shift mask to next bit
- dec di ;pt to next byte of strg
- loop L1 ;go do the next byte
- L3: pop si ;
- pop di ;
- popf ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _binary_to_char ENDP
- _TEXT ENDS
- END