Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

New Style lookup table

Status
Not open for further replies.

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
Is this lookup table possible

retlw d'1'
retlw d'2'
goto abc
retlw d'3'
retlw d'4'
goto xyz
retlw d'5'

:evil:
 

any reply or idea to use goto in table or making goto table as belwo

goto table

table:
goto aa
goto ab
goto ac
.........................
 

Yes it does work but be careful, if you are calling the look-up table as a subroutine, there isn't a problem if retlw is used because it works as a 'return from subroutine' instruction and pops the stack pointer. If you use 'goto' instead you must remember that the routine you are going to must finish with either a retlw or return instruction.

Also be careful if the look-up table crosses a page boundary because jumping ahead by adding a value to PCL will not also update the paging bits.

Brian.
 

Sorry cant understand this and if i call a table and goto some other location the return will returned me in look up table i think and again need return next to go back from look-up table

Also be careful if the look-up table crosses a page boundary because jumping ahead by adding a value to PCL will not also update the paging bits.

:???:
 

No, that is incorrect.

The instruction calling the table pushes the return address on to the stack. It stays there until the next retlw or return instruction is encountered. If your table contains a 'goto' the stack still holds the address of the original call instruction and that is where the program flow will continue from.

Brian.
 
  • Like
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
ya thats the thing i want to ask :p
 

My other comment about crossing page boundaries:

The jump into the look-up table is made by adding a value to PCL. As PCL is the lower part of the program counter, changing it makes the program fetch the next instruction from the calculated address. For example if the program address is 0x80 and you add 0x05 to PCL, the next instruction is picked up from 0x85, that how the jump table works. But (it's a BIG but), the PCL register is only 8 bits wide so when adding a value to it makes it overflow, the most significant bit is lost and the address rolls round to zero. It does not automatically move to the next page, doing that requires the paging bits in the STATUS register be changed as well. For example, consider this table, I've typed the address in the first column to demonstrate the problem:

my_table:
00FC addwf PCL,f
00FD retlw 11
00FE retlw 22
00FF retlw 33
0100 retlw 44 ;note that the page boundary is crossed
0101 retlw 55
0102 retlw 66
0103 retlw 77

If called with W equal to 0, 1 or 2 it returns 11, 22 or 33 as expected.
If called with a number higher than 2 it doesn't work, the reason being that PCL, being 8 bits wide, ignores that the top of the address has changed from 00 to 01. So instead of returning values from the table, the program jumps to a new address in the bottom of memory and tries to continue from there. Calling it with w = 3 for example would make the program jump to address zero. It is further compounded because having jumped to the wrong address, it still has the original return address on the stack. It would almost certainly cause a crash.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top