Modifying cnt?
DragonRaider5
Posts: 13
Hey,
I'm currently reading the CMUcam4 firmware in order to understand how to read the internal camera and then process the image. But there is one part which made me wondering what exactly its purpose is/how it works:
Thanks in advance,
DragonRaider5
I'm currently reading the CMUcam4 firmware in order to understand how to read the internal camera and then process the image. But there is one part which made me wondering what exactly its purpose is/how it works:
mov cnt, #7 ' Align instructions. Can be 6, 7, or 8. if_nz add cnt, #8 ' add cnt, cnt ' waitcnt cnt, cntMy problem is: The manual states, that you should not use cnt as a target register in asm. However here this is what is beeing done so what's this doing for the program? I know what cnt is but I dont know why you would change it
Thanks in advance,
DragonRaider5
Comments
Knowing that, your code first stores the number 7 in register $1F1, then adds the number 8 to the value in register $1F1 if the z flag is not set, then adds the value of the system counter into register $1F1, and then waits until the system counter equals that value. Since the source field of the waitcnt instruction is cnt, the value of the system counter is added to register $1F1 after the waitcnt is finished. I can't imagine how this last step is useful, but it likely doesn't matter, since it's very possible that the value in register $1F1 isn't used again (i.e. that the next operation that affects it is a mov that completely overwrites it).
The following code will compile to exactly the same machine code. However, I wouldn't recommend using the following code without renaming tmp to something like tmpd to indicate that you can only use it in the dest field (otherwise you'll get the value of the system counter).