Am I correct to say that a zero in W would result in an infinite loop in the table lookup code:
Code:
Table
addwf PCL,F
retlw 'a'
retlw 'b'
....
If W is "0", then it will not change PCL, the next instruction is then executed and the literal 'a' is return in W. Or will the next instruction be the Addwf itself?
If W is "1", then PCL is modified to point to the retlw 'a' instruction so again it will return the lateral 'a' in W.
here during the add, pcl will be incremented by 1 (so that it will point loc of retlw 'a'), after that pcl will be increment(normal increment) -> loc of retlw 'b' .
here during the add, pcl will be incremented by 1 (so that it will point loc of retlw 'a'), after that pcl will be increment(normal increment) -> loc of retlw 'b' .
Thanks for the explanation. The explanation fits nicely.
I didn't expect PC to be incremented after the Addwf PCL instruction as the operation is known as the computed GOTO with PCL changed. PC is definitely NOT incremented after the normal goto or call instruction after undergone a similar PCL changes.
Apparantly the PC has already been incremented when the addwf instruction is being executed. So there is no need for a post increment after the instruction finished.
My understanding is that the programme counter is incremented at the start of the execution cycle so it is pointing at the next instruction while the CPU is executing the previous.
Instructions such as goto, call, etc. cause the PCL to be altered. However, in the case of a call, the programme returns to the instruction after the call (as it must) since the PCL value is stored in the stack.