I really just want you to know I'm reading your code - very good stuff. I like how you work with the API. :)
I change this, too:
@@TIMER:

mov eax,Counter
xor Counter,1
invoke SendMessage,hWnd,WM_SETICON,0,[hIcons][eax*4]
jmp @r0
An interesting question I have is what is the smallest non-branching code to create periodic counter. The timer above has period of 2 (0,1), but how would we do period 3 (0,1,2) without branching? And greater periods... What about further restrictions: no cmp/sub.
Posted on 2002-05-06 22:18:31 by bitRAKE
but how would we do period 3 (0,1,2) without branching

easy way for any number - table of increasing indexes with
0 index at the end. (for 7)
stbl db 1,2,3,4,5,6,0
state db 0
.code
movsz eax,state
mov al,stbl
mov state,al
invoke SomeFunc,
Posted on 2002-05-10 14:36:31 by The Svin
Since there is no respond, I show another one way, waiting for
your versions:
without branche and table for number of states = power of 2

for 8 states:
state dd 0
.code
mov eax,state
inc eax
and eax,7
mov state,eax
;when state aproaches 8 it becomes 0 again and cirle repeats
if you choose to reply - it's better move the thread to algo section.
since now it regards algo topics
Posted on 2002-05-10 15:23:32 by The Svin
.data
state dd 00000000000010000000001000000000y
.code
mov eax, state
shr eax,32-2 ; 0,1,2
rcl state,11

A byte would work too:

.data
state db 00000101y
.code
movzx eax, state
; last bit shifted out must be zero
shr eax,8-3 ; 0,1,2
rcl state,3

I haven't discovered a general shift xor algo, but will continue to think about it. I like the DWORD one above, many possible tri-state uses.
Posted on 2002-05-10 16:52:25 by bitRAKE
With cmp but without jcc and Anger way:


cmp al,1
adc al,al
and al,3

explanation:
al=0
cmp al,1 ;CF=1
adc al,al ;0+0+1=1
and al,3 ;al=1
al=1
cmp al,1 ;CF=0
adc al,al ;1+1+0=2
and al,3 ;al=2
al=2
cmp al,1 ;CF=0
adc al,al ;2+2=4
and al,3 ;al = 0
;)
Posted on 2002-05-11 07:01:12 by The Svin
Tricky Rickey ;)
ah=0

ror ah,1 ;ah=0
lahf ;S=0, Z=1
shr ah,6 ;1
ah=1
ror ah,1 ;ah=80h
lahf ;[COLOR=red]S=1[/COLOR], Z=0
shr ah,6 ;2
ah=2
ror ah,1 ;ah=1
lahf ;S=0, Z=0
shr ah,6 ;0
ERROR: ROR doesn't effect the sign flag.
Posted on 2002-05-11 10:37:15 by bitRAKE

An interesting question I have is what is the smallest non-branching code to create periodic counter.

Smallest?


mov dl,3 ; or greate
div dl
xor ah,ah
:)
Posted on 2002-05-11 11:10:26 by Nexo
Nexo, smallest means:

smallest number of bytes
smallest execution time
smallest number of instructions

Good solution.

Some part of me believes there must be a two instruction solution?
Posted on 2002-05-11 11:19:10 by bitRAKE
Yes.


cmp eax,3
cmove eax,ZERO
Posted on 2002-05-11 11:27:02 by Nexo
No, better make decrement ;)


dec eax
cmovs eax,NUMBER2
Posted on 2002-05-11 11:34:09 by Nexo
divide 0 any number = 0. Null wouldn't become 1 or 2.
dec + cmovs I think best possible solution, of course having problem with less than PPRO proc.
Posted on 2002-05-11 15:40:12 by The Svin
this is the best I could do. Not the smallest, but just another idea. Works for all byte constants

1) dec eax == (-1) xor (neg eax)
2) add 0,value == (value) xor (neg 0)



neg eax
cdq
or edx,byteconstant
xor eax,edx


8 bytes. Or using only eax, 9 bytes



neg al
cbw
or ah,byteconstant
xor al,ah


maybe you guys can do something with this to make it smaller??

--Chorus
Posted on 2002-05-11 22:58:14 by chorus
another simple idea, to make periodic of 3 play metro-rithm pattern qouter, quoter,half.
state dd 01020000h


.code
mov eax,state
rol eax,8
mov eax,state
and eax,0FFh
; [tbl][eax*4]


BTW: is there a way that musicians can write rithm pattern in
ASCII? Including length of pause, metro-size etc. ?
Posted on 2002-05-12 10:06:32 by The Svin
I just have a simple thought SETcc could lead to many interesting periodic solutions, in various manner.
Posted on 2002-06-02 09:32:41 by The Svin