PIC Assembly programming relocatable or absolute

Thread Starter

stahta01

Joined Jun 9, 2011
133
I am a Teaching Assistant for a PIC programming class; the instructor uses absolute code when teaching PIC16F Assembly programming.

What are the advantages of absolute code over relocatable code?

The advantages I can think of are:
The Assembler is easy to write; but, does not really matter to me.
There seem to be more examples of absolute code on the internet.

The disadvantages I can think of are:
It is harder to link many asm file together; because two files may wish to use the same file/data or code location.

I personally would like to change to relocatable code; so, I am thinking of re-writing all the sample projects as relocatable.

I just wish to know if there is any advantage of absolute code that I am missing.

Tim S.
 

ErnieM

Joined Apr 24, 2011
8,377
From the fine manual inside MPLAB, found by clicking Help | Topics... MPASM Assembler:

Assembler Operation: said:
The MPASM assembler can be used in two ways:

  • To generate absolute code that can be executed directly by a microcontroller.
  • To generate relocatable code that can be linked with other separately assembled or compiled modules.
Generally you only need relocatable code when you are building a library function to be used inside another project. The library need not be rebuilt every compile, or you can just release the precompiled library without releasing your underlying source code.
 

Thread Starter

stahta01

Joined Jun 9, 2011
133
@ErnieM:

I agree with your statement; but, I am not sure if it supports either side.

Your quote says relocatable code requires a linker; I know that. Edit: This implies harder to do; a minus.

I just wonder which is used more by real programmers in the field; if it is absolute code, no reason to change.

As it is, I am afraid that relocatable code is used more in the real world and the student are not learning how to do it.
Edit: I have no real facts to base this on.

So, I was thinking to get a list of advantages of both; in order to convince the professor to change to relocatable code. But, I am not really sure if it is a good idea myself. So, I need to first decide if it really is a good idea to change.

Edit: For those who do not know Directives "org", "cblock", and "endc" are meant for absolute code; while Directives "code", "extern", "global", "udata", and "idata" are meant for relocatable code.

Tim S.
 
Last edited:
In 35 years of programming I have never used relocatable code.
I once wrote a linker but thats a different story.

If i want to use a library function I fit it in where it will fit without going over page boundaries.
 

ErnieM

Joined Apr 24, 2011
8,377
I agree with your statement; but, I am not sure if it supports either side.
Taking sides on this is like taking sides on the hammer vs screwdriver debate, which is the better tool?

Are you driving nails? The screwdriver makes a poor choice.

Are you driving screws? The screwdriver makes the better choice.

Are you building an executable? Then absolute code the better choice.

Are you building an reusable library? Then absolute code is a poor choice.

If you look close at the Output window in MPLAB when you build some code you will notice that the linker is also used for absolute code. There is a default linker script that is being used.

nigelwright7557 said:
In 35 years of programming I have never used relocatable code.
QFT. I don't believe I have ever used relocatable code either, though it was possible when I was creating activeX objects under Win98 inside assembly language dll's

Aside@nigelwright7557: I think I may have 1 year on you, I started summer of '75.
 

ErnieM

Joined Apr 24, 2011
8,377
I am a Teaching Assistant for a PIC programming class; the instructor uses absolute code when teaching PIC16F Assembly programming.
You guys have never programed in C before?

C almost always uses relocatable code.
I haven't used C to program a PIC since... well... this morning while finishing off a bootloader using an SD drive on a PIC32 platform.

Any way you start off the code you need to provide absolute code that executes inside the processor.

You started this thread to discuss Assembly programming. Are you trying to hijack your own thread?
 

Thread Starter

stahta01

Joined Jun 9, 2011
133
And, the class teaches C programming on the PIC 16F line.
I am trying to find out if people in the real world really does not use relocatable code when doing Assembly. But, you two made blanket statements about always using absolute code and I was not sure you both really understand what the difference was between the two.

If I ever needed to mix C and Assembly I would assume the Assembly relocatable code would mix best with C Code; but, I have idea if this is true on the PIC Compiler line. It is true on some old Motorola line, example 6809 for the Microwave C Compiler.

From what you are all saying very few people use Linker Scripts for PIC Assembly programming (which I believe implies relocatable code).

Tim S.
 

Thread Starter

stahta01

Joined Jun 9, 2011
133
Current feedback is that only teaching absolute code (instead of relocatable) in PIC (16F) Assembly is perfectly acceptable. It is counter to my personal opinion; but, I am more of an high level programmer than Assembly programmer. So, it might be my lack of real world projects using Assembly that is causing my bias.

Tim S.
 

Thread Starter

stahta01

Joined Jun 9, 2011
133
Based upon your summation I must assume you didn't read any of our replies.

<thread closed>
You have NEVER use relocatable Code in PIC Assembly; but, you think it is NOT OK to just leave it at Teaching Absolute code in PIC Assembly. I read all of you replies; note, I must have NOT understood them based on your reply.

Tim S.
 
Top