home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
BIN2INT.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
59 lines
;unsigned short binary_to_int(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_int
_binary_to_int 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,17 ;must find end of string
mov al,0 ;
cld ;
repne scasb ;go scan for terminating zero
jnz L3 ;quit if string over 16 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_int ENDP
_TEXT ENDS
END