Society of Robots - Robot Forum
Software => Software => Topic started by: mpuvdd on March 29, 2008, 09:38:37 AM
-
HI everyone,
I'm learning C and some assembly language currently, and was told that $ + 1 would delay 2 instruction cycles instead of 1. Shouldn’t it just take 1 instruction cycle? How's that work? Also, $ does stand for PCL, right?
Thanks,
mpuvdd
-
Which assembly language standard is this for?
-
I'm not sure? I'm using MPLAB IDE as a compiler, but that's all I know.
-
I think that $ + 1 is shorthand for adding 1 to the PC register (program counter).
In a normal instruction, where the PC isnt modified, the PC automatically increments itself (which doesn't take a cycle). But when it's been modified, the MCU has to first jump to the new location (which takes a cycle) , before executing it. This adds the extra cycle. The $ + 1 just tricks the MCU into thinking the PC has been modified.
I think thats basically it.
Heres a webpage which goes into more detail (see the pipelining section) - http://www.mikroe.com/en/books/picbook/2_01chapter.htm (http://www.mikroe.com/en/books/picbook/2_01chapter.htm)
-
$ is a symbol reffering to current line. It's a shorthand for doing short jumps (although longer ones can be performed, too).
Less labels mean less clutter, so instead of doing a jump with "goto here", you can simply write "goto $+2".
it will not alter the PC in any different way than a goto does. It's just a different way of determining the jump location.