loop x times in pasm
bennettdan
Posts: 614
Hello how would you go about looping a certain number of time in a pasm loop?
Comments
Try it, it's fun!
Jim
djnz = Decrement <variable> and jump if not zero.
For any loop count greater than 511 you need to generate the value another way, as an immediate can't hold a value that large. Most people just create a variable in the DAT section and set it to the value needed, then copy it out, like this:
Uh... I'm a little slower than Dave Hein and JasonDorie.
For clarity, each of the preceding instructions takes a long value in cog memory, so doing it this way works, but it's very wasteful compared to the single MOV instruction and DAT statement version, which is 2 longs total compared to Dave's 7.
The djnz instruction is also one long, compared to the sub + conditional jmp of Dave's method. I'm quite sure Dave knows all this and is just being cheeky, but I thought it was worth pointing out because someone just starting out isn't likely to know the difference.
And hence, I have out-cheeky'd Dave.
mov counter, #500
shl counter, #1 ' double the value.
Andy
Andy