confusion for lookup table of pic controller

Status
Not open for further replies.

mrarslanahmed

Full Member level 2
Joined
Nov 15, 2011
Messages
143
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Location
gujranwala pakistan
Visit site
Activity points
2,206
hi all i am working on pic assembly and need ur help .

i implemented a lookup table

instead of accessing the table through a call instruction what if i call it through goto instruction.. would the retlw gets the same value or it would be different.
 

It will load the value into W just the same as if you called it but the stack will go out of balance. The RETLW instruction works as a subroutine return as well as carrying a value back in W so it will pick up the value and then jump to whatever address is on the stack. When you 'call' it you put the return address on the stack so it knows where to go back to but if you 'goto' it, the return address will be missing and it could go anywhere. It will almost certainly crash your program.

It is possible to create a table of jump addresses by simply adding a value to the program counter then following it with a list of 'goto' instructions. It will goto the routine W places ahead of the add instruction. If you do this, be very careful that you don't cross a page boundary as the PCLATH register is not updated.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…