Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC table lookup with W=0

Status
Not open for further replies.

eblc1388

Active Member
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.
 
If W is "0", then it will not change PCL, the next instruction is then executed and the literal 'a' is return in W.
correct
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' .
 
akg said:
If W is "0", then it will not change PCL, the next instruction is then executed and the literal 'a' is return in W.
correct
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' .
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.
 
I have found the answer to the question.

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.
 

Attachments

  • pcl.gif
    pcl.gif
    10.7 KB · Views: 367
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.
 
Status
Not open for further replies.

Latest threads

Back
Top