Because EBX is independantly incrementing, you can replace the 8 add ebx, 4 by a single addition add ebx, 4*8.
You can avoid all of those ugly and time consuming conditional jumps by using the conditional set instruction setl (Set On Less).
Because fails and passes are mutually exclusive, you can defer from calculating the passes to the very end. e.g. If processing 8 values gave 3 fails then there inevitably have to be 5 passes (is 8 minus 3).
xor ecx, ecx ;Clear because SETL only operates on a byte xor edx, edx ;Clear temporary counter of fails cmp val1, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val2, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val3, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val4, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val5, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val6, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val7, 40 setl cl add edx, ecx ;Conditionally increment temporary counter cmp val8, 40 setl cl add edx, ecx ;Conditionally increment temporary counter add fails, edx ;Add temporary counter to actual variable sub edx, 8 sub passes, edx ;Add complementary count to other variable (*) add ebx, 4*8
I was wondering if I create a single failinc and passinc subroutine with ret in it how can I call it after cmp ?
Now the subroutine
AddTempCount: ;On input EFLAGS is set from CMP instruction setl cl add edx, ecx ;Conditionally increment temporary counter ret
can improve the readability a bit.
xor ecx, ecx ;Clear because SETL only operates on a byte xor edx, edx ;Clear temporary counter of fails cmp val1, 40 call AddTempCount cmp val2, 40 call AddTempCount cmp val3, 40 call AddTempCount cmp val4, 40 call AddTempCount cmp val5, 40 call AddTempCount cmp val6, 40 call AddTempCount cmp val7, 40 call AddTempCount cmp val8, 40 call AddTempCount add fails, edx ;Add temporary counter to actual variable sub edx, 8 sub passes, edx ;Add complementary count to other variable (*) add ebx, 4*8
(*) Subtracting a negative count is the same as adding a positive count.
callasm command:call - retpair - google itcallbut my issue is how to call it only if thecmp eax, 40is below 40. That is what I am struggling withmov\inc\movreplaced withcall. Btw you caninc failsdirectly.