Code Optimization
Kye
Posts: 2,200
Hello, all I've been busting my head on how to do something in asm much more simply, but I just can't seem to get it done.
Here's the code..
Basically, I need to use waitcnt for a state machine at specific times·in my code. The piece above is run inside a loop that loops 26 times. Every four loops I need to execute the waitcnt which is what this code does.
Now, I want to make it more optimized by using the c flag only so I don't need to backup the z flag since I'm using it within the loop. The problem is however, that there's a sweet spot. The code above executes that sweet spot. To say, waitcnt must only be executed on the 22, 18, 14, 10, 6, 2 parts in the loop. Note that the loop counts down from 26 so the execution of the coditional for 2 is last and 26 is first.
I can't seem to figure out how to do this with the c flag...
Any ideas?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Here's the code..
muxnz keyBuffer, #1 ' Backup Z flag. cmp keyArrayCounter, #2 wz ' Wait a little while to synchronize. if_nz cmp keyArrayCounter, #6 wz ' if_nz cmp keyArrayCounter, #10 wz ' if_nz cmp keyArrayCounter, #14 wz ' if_nz cmp keyArrayCounter, #18 wz ' if_nz cmp keyArrayCounter, #22 wz ' if_z waitcnt keyTimeBuffer, clockWait ' test keyBuffer, #1 wz ' Restore Z flag.
Basically, I need to use waitcnt for a state machine at specific times·in my code. The piece above is run inside a loop that loops 26 times. Every four loops I need to execute the waitcnt which is what this code does.
Now, I want to make it more optimized by using the c flag only so I don't need to backup the z flag since I'm using it within the loop. The problem is however, that there's a sweet spot. The code above executes that sweet spot. To say, waitcnt must only be executed on the 22, 18, 14, 10, 6, 2 parts in the loop. Note that the loop counts down from 26 so the execution of the coditional for 2 is last and 26 is first.
I can't seem to figure out how to do this with the c flag...
Any ideas?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Any other ideas anyone?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Reversing the lower 2 bits of tmp will zero out all upper 30 bits, and will leave a 1 in tmp if the original value would have been a 2. Then the DJNZ jump to :skip_pause if the value of tmp was not 1.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
* bows *
[noparse][[/noparse]8^)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.