flat assembler
Message board for the users of flat assembler.

Index > Windows > check how many functions failed

Author
Thread Post new topic Reply to topic
randomdude



Joined: 01 Jun 2012
Posts: 83
randomdude 26 Mar 2014, 11:33
so i have been using this to know the number of functions that have failed

Code:
        xor     ebx,ebx
        xor     edi,edi ;fuck, i need addzx instruction :S
        invoke  RegisterHotKey,0,VK_F5,0,VK_F1
        test    eax,eax
        setz    bl
        add     edi,ebx
        invoke  RegisterHotKey,0,VK_F6,0,VK_F2
        test    eax,eax
        setz    bl
        add     edi,ebx
        ...    


edi = number of functions that returned 0

but im feeling that this is not the best way. does anyone know how can i optimize it?
Post 26 Mar 2014, 11:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 26 Mar 2014, 16:14
Use a table maybe:
Code:
hot_key_table:
dd VK_F5,VK_F1
dd VK_F6,VK_F2
dd 0
;...
xor edi,edi
mov esi,hot_key_table
.loop:
invoke  RegisterHotKey,0,dword[esi+0],0,dword[esi+4]
test eax,eax
setz al
movzx eax,al
add edi,eax
add esi,8
cmp dword[esi],0
jnz .loop    
Post 26 Mar 2014, 16:14
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 26 Mar 2014, 17:13
Given that RegisterHotKey return type is BOOL, it might be as simple as invoke/add edi,eax with a cmp at the end.
Post 26 Mar 2014, 17:13
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 26 Mar 2014, 18:33
I don't think we can assume MS bool is 0 or 1, right?
I just had an idea for edi += BoolToInt(eax), I think it should work because adding eax to 0xFFFFFFFF only doesn't produce a carry when eax is zero.
Code:
; increment edi if eax != 0
neg  eax    ; or add  eax,-1   ; carry flag is now the bool represented by eax
adc  edi,0                     ; increment edi by carry flag     

I don't think you can do do this with fewer than 2 instructions.

Also,
Code:
; increment edi if eax = 0
cmp  eax,1  ; or sub  eax,1    ; carry flag is now the bool represented by !eax
adc  edi,0                     ; increment edi by carry flag     


Last edited by tthsqe on 27 Mar 2014, 03:31; edited 2 times in total
Post 26 Mar 2014, 18:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20340
Location: In your JS exploiting you and your system
revolution 26 Mar 2014, 23:37
I think it is not safe to assume bool returns -1 for true. It might return +1, or 482. Glad to see tthsqe saw that. Anyhow, it hardly seems worth the effort to save a single instruction for an API call that executes an unknown number of instructions and in a place that is called only once upon program startup.
Post 26 Mar 2014, 23:37
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 27 Mar 2014, 01:50
tthsqe,

neg instruction does exactly that (sets CF if operand is non-zero, clears otherwise), though its primary function may render it unusable in this case.

cmp eax, 1 could be better than sub eax, 1.
Post 27 Mar 2014, 01:50
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 27 Mar 2014, 03:27
baldr, I though 'neg' doesn't affect carry flags, or is that 'not'? I don't know because I never use those...
Anyways I read the docs and changed my post.
Post 27 Mar 2014, 03:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.