Bob Ammerman wrote: > Please take the time to carefully read and understand the following. It w= ill > probably solve your problem. Perhaps more importantly, if you study it > closely, you will have a much better handle on how the assembler and link= er > interact. > > > If var were at a known address at assembly time (say in an absolute secti= on) > then you might think it would work because the assembler could resolve th= e > expression itself without involving the liker. Unfortunately that is not = the > case. Assume 'var' is in a absolutely addressed section like this: > > myseg udata H'20' > var res 1 > > You would think the assembler should be able to determine that low(0-var) > was simply H'E0'. However, even this won't work. The assembler does not > 'know' in its symbol table that 'var' is in an absolutely addressed secti= on > and thus has an address that could be known at assembly time. > > The only way that I can think of to make this work would require a trick > like this: > > work_abs equ H'30' > work udata work_abs > work_base: > > adummy res 3 > > var_abs =3D ($-work_base)+work_abs > var res 1 > > > mycode CODE > > movlw low (0-var_abs) > > > This, no doubt, needs some explanation. Let's take it one line at a time.= ... > > [1] work_abs equ H'30' > > This is creating an assembly time symbol containing the absolute value > H'30'. This is where we plan on placing our variables. > > [2] work udata work_abs > > This is declaring a data section, and tells the linker exactly where it h= as > to appear in memory. Now the linker and the assembler agree on where the > data will go. It is critical to understand that for this to work our sect= ion > must be located at a location known at assembly time (ie: at 'work_abs'). > > [3] work_base: > > This is declaring another symbol to the assembler. This one is a relocata= ble > symbol with the value "0 in the 'work' section". > > [4] adummy res 3 > > This line is here just to show that other variables can be declared as > normal in the 'work' section. > > [5] var_abs =3D ($-work_base)+work_abs > > This line contains the 'magic' that makes this whole scheme work. We'll t= ake > it apart to understand what it is doing: > > The dollar sign is a pseudo symbol for the current offset in the current > section. Thus at this point it has the value "3 in the 'work' section". > > Work base, as described above is also a symbol with the value "0 in the > 'work' section". > > Thus, $-work base is computed by the assembler as just plain 3, because t= he > "in the 'work' section" parts of the two symbols cancel in the subtractio= n. > > Next we add in work_abs, which you will remember is the absolute value > H'30'. This gives us the absolute value H'33', which of course is where t= he > linker is going to end up putting 'var'. > > [6] var res 1 > > Allocates the 'var' inside the 'work' section. It is important to note th= at > 'var' is now a symbol with the relocatable value "3 in the 'work' section= ". > > [7] mycode CODE > > Just moving to the code section so we can put in instructions. > > [8] movlw low (0-var_abs) > > The argument to 'low' is the difference of two _absolute_ expressions. Th= e > result, of course, is also absolute, and so the assembler is happy with i= t. > > -- Bob Ammerman > RAm Systems > Thank you very much for your detailed explanation this was very helpful!=20 Now I understand the problem. Your words helped me to understand the way=20 the assembler and linker talk to each other. Now I am left with the impression that there is something generally=20 wrong with this kind of one way communication between them. Once again, thanks, your answer is highly appreciated! Kind regards, Svetlin --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .