Relocation tables are used in programs that float around in RAM somewhere, and don't have a fixed starting point. An example are all the C libs, they won't be executed from UserMem, but are somewhere in RAM. However, the C libs does have SMC and jp's, so it's necessary to know the right location where to SMC/jump, and that is where a relocation table jumps in. This is just a table at the start of the program, with all the pointers to the jp's/SMC's in it. When you run a C program, LibLoad reads each lib, and because it sees a relocation table, it relocates all the necessary SMC's/jp's.
What I did in AoCE was, using a macro (.r), which stores the address in a separate file, and then include that file in the main program.
Check this program, which creates my relocation table (although it's stored at the
end of the program:
Code: #macro relocate1()
#ifdef old_addr
.echo >> relocation_table1.asm "\t.dl ",$ - new_addr + old_addr - 3,"\n"
#else
.echo >> relocation_table1.asm "\t.dl ",$-3,"\n"
#endif
#endmacro
#define .r1 relocate1()
#macro relocate2()
#ifdef old_addr
.echo >> relocation_table2.asm "\t.dl ",$ - new_addr + old_addr - 3,"\n"
#else
.echo >> relocation_table2.asm "\t.dl ",$ - 3,"\n"
#endif
#endmacro
#define .r2 relocate2()
#macro relocate(addr)
#define old_addr eval($)
.org addr
#define new_addr eval($)
#endmacro
#macro endrelocate()
.org $-new_addr+old_addr
#undefine old_addr
#undefine new_addr
#endmacro
.echo >> relocation_table1.asm "RelocationTable1:\n"
.echo >> relocation_table2.asm "RelocationTable2:\n"