STR2BIN will convert a positive string value to binary at the selected base.
STR2BIN
string is terminated with zero byte
al=base (min=2)
ds:edx=string start
ebx=return value
cf=return set if invalid charactors for base found
used registers restored except ebx & flags
------------------------------------------
This little test program shows STR2BIN with the in-string printed then showing the out-value (remember the first byte is least significant).
.386p
.MODEL SMALL
.STACK 200h
.DATA
key1 db '4142A344=$'
key2 db '4142A344',0h
key3 db '0000$'
.CODE
myproc proc
jmp main
STR2bin proc near
;IN:al=base,ds=selector,edx=offset OUT:ebx=value,cf=error
push eax
push ecx
push edx
push ebx
xor ecx,ecx
mov cl,al
xor eax,eax
STR2bin1: xor ebx,ebx
mov bl,[edx]
cmp bl,0h
je STR2bin0
cmp bl,030h
jl STR2binE
cmp bl,03Ah
jl STR2bin3
sub bl,07h
cmp bl,03Ah
jl STR2binE
cmp bl,03Fh
jg STR2binE
cmp bl,al
jge STR2binE
STR2bin3: sub bl,030h
cmp bl,cl
jg STR2binE
push edx
xor edx,edx
mul ecx
add eax,ebx
pop edx
inc edx
jmp STR2bin1
STR2binE: stc
pop ebx
jmp STR2bin2
STR2bin0: clc
mov ebx,eax
pop edx
STR2bin2: pop edx
pop ecx
pop eax
ret
STR2bin endp
main proc near
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset key1
int 21h
mov al,0Bh
xor edx,edx
mov dx,offset key2
call STR2bin
jnc main0
mov ebx,' RRE'
main0: mov eax,ebx
xor ebx,ebx
mov bx,offset key3
mov [bx],eax
mov ah,9
xor edx,edx
mov dx,offset key3
int 21h
mov ax,4c00h
int 21h
main endp
myproc endp
end myproc
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"