Hi
Gives a solution for check if valid char in a string
If not give me a result for invalid string
WIth a Editbox it this simply with
.if uMsg==WM_CHAR
mov eax,wParam
.if (al>="0" && al<="9") || (al>="A" && al<="F") || (al>="a" && al<="f") || al=="-" || al==VK_BACK
.if al>="a" && al<="f"
sub al,20h
.endif
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
ret
.endif
My why is now with a character table
szValidChars db "ABCDEF1234567890-",0
Have your an idea?
REPNE SCASB will scan a string (your "table") for a byte (the input char)
What are you trying to achieve? Faster processing? If you want raw speed you could use a 256 entry lookup/translate table
Also doing the tests in this order would be more efficient (ie faster)
mov eax,wParam
.if al>="a" && al<="f"
sub al,20h
.endif
.if (al>="0" && al<="9") || (al>="A" && al<="F") || al=="-" || al==VK_BACK
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
ret
.endif
no i coding a tool without a resource (dialog)
less double testing
mov eax,wParam
.if al>="a" && al<="f"
sub al,20h
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
ret
.elseif (al>="0" && al<="9") || (al>="A" && al<="F") || al=="-" || al==VK_BACK
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
.endif
ret
or how i would write. May be awful, sorry if it is. You'll be waiting on that CallWindowProc anyways :)
movzx eax, wParam
cmp al, 008h ; VK_BACK
je OldProc
cmp al, 02Dh ; "-"
je OldProc
cmp al, 030h ; "0"
jb NoProc
cmp al, 03Ah ; "9"+1
jb OldProc
cmp al, 041h ; "A"
jb NoProc
cmp al, 047h ; "F"+1
jb OldProc
cmp al, 061h ; "a"
jb NoProc
cmp al, 066h ; "f"
ja NoProc
sub al,20h
OldProc: invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
NoProc: ;xor eax,eax ; probably want to return zero. not sure what you want
ret
maybe i'm missing something :P
but, shouldn't the RET be outside the IF structure ?
mov eax,wParam
.if al>="a" && al<="f"
sub al,20h
.endif
.if (al>="0" && al<="9") || (al>="A" && al<="F") || al=="-" || al==VK_BACK
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
.endif
ret
@Joe - Yes, I'd probably write it in real assembler too.
@Dave - Hard to say, ragdog only provided a code fragment, so just tried to match the fall-through behaviour.
Hi
Ok i have solved it
.data
szHexAllowed db '0123456789ABCDEFabcdef ',0
.code
mov eax, wParam
mov edi,offset szHexAllowed
mov ecx,sizeof szHexAllowed
repnz scasb
.if zero?
.if al > '9'
and al,not 20h
.endif
invoke CallWindowProc,hOldProc,hWnd,uMsg,eax,lParam
ret
.endif
I hope your undstand now what i mean
Greets
i liked Clive's idea of a 256-byte LU table :U
Why?
well - although it requires a 256-byte table, it would be easy to generate - the table doesn't have to be pre-defined
once you have the table made, this is probably the fastest conversion method - a very simple loop
the table needs to be generated once at program initialization
the code can probably be made even smaller :P
but, this will give you an idea...
.DATA?
HexTable db 256 dup(?)
.CODE
;--------------------------------------------------------------------------------
TableInit proc
xor eax,eax
mov edx,offset HexTable
mov ecx,64
push edx
Table1: mov [edx],eax
add edx,4
dec ecx
jnz Table1
pop edx
mov al,8
mov [edx+eax],al
mov al,2Dh
mov [edx+eax],al
mov cl,10
mov al,30h
Table2: mov [edx+eax],al
inc eax
dec ecx
jnz Table2
mov al,41h
mov cl,6
Table3: mov [edx+eax]al
mov [edx+eax+20h],al
inc eax
dec ecx
jnz Table3
ret
TableInit endp
;--------------------------------------------------------------------------------
then, to use it...
mov eax, wParam
mov al,HexTable[eax]
or eax,eax
jz No_Proc
invoke CallWindowProc,hOldProc,hWnd,uMsg,eax,lParam
ret
No_Proc: