C code
*************************
.if fun(a,b)

.elseif fun(c, b)

.elseif fun(d, b)

*************************
I mean that beforte "if" or "elseif" there must call a function, but the "if" of masm must be register, so how can you do this?

thanks
Posted on 2005-01-28 03:02:10 by jndk
i use

.if FUNC( fun, a, b)
.........
.elseif FUNC(fun, b, c)
.......

but cannot work correctly, it only call first fun, not call any other, is there any bug in FUNC macro?
Posted on 2005-01-28 03:05:07 by jndk
Roll your own IFs...


invoke fun, a, b
or eax, eax
jz @F

...
jmp the_end
@@:
invoke fun, c, b
or eax, eax
jz @F

...
jmp the_end
@@:
invoke fun, d, b
or eax, eax
jz the_end

...
the_end:


Mirno
Posted on 2005-01-28 06:42:15 by Mirno
i think is more easy like below


.if FUNC( fun, a, b)
........
jmp @end
.endif
.if FUNC( fun, c, d)
.............
jmp @end
.endif

@end:
ret


but i want to know why .if FUNNC, elseif FUNNC cannot work
Posted on 2005-01-28 07:01:39 by jndk
Isn't it better to use



invoke func,a,b
test eax, eax
jnz exit
invoke func,c,d
test eax, eax
jnz exit
...
exit:
Posted on 2005-01-28 07:36:10 by roticv
helhe

i think


.if FUNC( fun, a, b)
........
jmp @end
.endif
.if FUNC( fun, c, d)
.............
jmp @end
.endif

@end:
ret

is easy to understand
Posted on 2005-01-28 07:56:51 by jndk
but any one know why .if FUNNC, elseif FUNNC cannot work

the second FUNNC cannot work???
Posted on 2005-01-28 07:58:33 by jndk
It has to do with the structure of the .IF block syntax that the subsequent FUNC() calls are never evaluated. Either use a seperate .IF block after each or manually code it with test eax, eax.
Posted on 2005-01-28 08:12:48 by hutch--
i write atoi



atoi proc uses ebx esi edi lpst:DWORD
xor ecx, ecx
mov edi, lpst
@@: movzx esi, BYTE ptr [edi]
.if esi
.if esi=='0' || esi=='1'|| esi=='2'|| esi=='3'|| esi=='4'|| esi=='5'\
|| esi=='6'|| esi=='7'|| esi=='8'|| esi=='9'
mov eax, ecx
mov ebx, 10
mul ebx
add eax, esi
sub eax, '0'
mov ecx, eax
.else
mov eax, ecx
ret
.endif
inc edi
jmp @B
.endif
mov eax,ecx
ret
atoi endp
Posted on 2005-01-28 08:28:05 by jndk
Dear hutch--
i fond your are professor in masm, but may i have your msn, and i can learn from you more easy
Posted on 2005-01-28 08:30:52 by jndk
jndk,

C code
*************************
.if fun(a,b)

.elseif fun(c, b)

.elseif fun(d, b)

*************************


I think the following code will do what the above does.



MASM code
*************************
INVOKE fun,a,b
TEST EAX,EAX
.IF ZERO?
...........
.ELSE
INVOKE fun,c,b
TEST EAX,EAX
.IF ZERO?
............
.ELSE
INVOKE fun,d,b
TEST EAX,EAX
.IF ZERO?
..........
.ELSE
........
.ENDIF
.ENDIF
.ENDIF
*************************




atoi proc uses ebx esi edi lpst:DWORD
xor ecx,ecx
mov edi, lpst
@@: movzx esi, BYTE ptr [edi]
.if esi ;THIS .IF IS REDUNDANT, THE .IF BELOW WILL SUFFICE
.if esi=='0' || esi=='1'|| esi=='2'|| esi=='3'|| esi=='4'|| esi=='5'\
|| esi=='6'|| esi=='7'|| esi=='8'|| esi=='9'
mov eax, ecx ;THIS INSTRUCTION IS USELESS BECAUSE MUL BELOW WILL WIPE OUT EAX
mov ebx, 10
mul ebx
add eax, esi
sub eax, '0'
mov ecx, eax
.else
mov eax, ecx
ret
.endif
inc edi
jmp @B
.endif
mov eax,ecx
ret
atoi endp


The following is a simplification of your above code. Further simplifications are possible. Ask if you are interested. Notice the notes I added to your above code. Ratch



ATOI:
ATOI$1 STRUC
savreg DWORD 2 DUP (?)
return DWORD ?
lpst DWORD ?
ATOI$1 ENDS

S$1 EQU ESP.ATOI$1

RPUSHIT ESI,EDI

MOV EDI,[S$1.lpst]
XOR ECX,ECX

.WHILE TRUE
MOVZX ESI,BYTE PTR [EDI]
.IF (ESI >='0') && (ESI<='9')
MOV EBX,10
MUL EBX
ADD EAX,ESI
SUB EAX,'0'
MOV ECX,EAX
.ELSE
MOV EAX,ECX
POPIT ESI,EDI
RET DWORD
.ENDIF

INC EDI
.ENDW
Posted on 2005-01-28 16:09:09 by Ratch
thanks a lot
Posted on 2005-01-28 21:07:47 by jndk


The following is a simplification of your above code. Further simplifications are possible. Ask if you are interested. Notice the notes I added to your above code. Ratch



ATOI:
ATOI$1 STRUC
savreg DWORD 2 DUP (?)
return DWORD ?
lpst DWORD ?
ATOI$1 ENDS

S$1 EQU ESP.ATOI$1

RPUSHIT ESI,EDI

MOV EDI,[S$1.lpst]
XOR ECX,ECX

.WHILE TRUE
MOVZX ESI,BYTE PTR [EDI]
.IF (ESI >='0') && (ESI<='9')
MOV EBX,10
MUL EBX
ADD EAX,ESI
SUB EAX,'0'
MOV ECX,EAX
.ELSE
MOV EAX,ECX
POPIT ESI,EDI
RET DWORD
.ENDIF

INC EDI
.ENDW



but i think there is bug in your program
if lpst only zero, will no return!!!
Posted on 2005-01-29 01:04:10 by jndk
jndk,
but i think there is bug in your program
if lpst only zero, will no return!!!


"lpst" can never be zero, or the program will error. "lpst" is an address within the program's data segment which never begins at zero. Ratch
Posted on 2005-01-29 01:40:04 by Ratch