Go Down

Topic: Program Counter (PC) (Read 3155 times) previous topic - next topic

westfw

#15
May 13, 2012, 06:01 am Last Edit: May 13, 2012, 06:03 am by westfw Reason: 1
At the machine instruction level, the AVR has several instructions for changing the PC based on a run-time variable.
There are "indirect" call and jump instructions (icall and ijmp) that set the PC to the contents of the Z register (R31:30).
But the more common technique for task switching is to arrange for the correct address to be at the top of the stack, and then do a "ret" return instruction.

Code: [Select]
void start_task(int startaddr)
{
  int * stack = malloc(stacksize);
  /*
   * set up stack
   */
   *stack = startaddr;
   // Other context
   setstackpointer(stack);  // usually magic assembler code for this
} // return goes to startaddr()


(I should note that "ijmp" is most like the PIC's "mov PCL, reg" instruction, and that the stack hack, while common on MANY architectures, is usually difficult to do on PICs since their hardware stack is not directly accessible to software.)


jcisne7

Hello again!

After seeing some friend's codes I realized that what  I was asking is not really what teacher asked us to do :lol:

Now I think I got it clearer...

Tasks code have to be previously written in the AtMega but I have to know where are they written (where they start and finish)

This is the first part... Can anyone pleas help me whit this?

I will really appreciate your comments...


AWOL

Quote
Tasks code have to be previously written in the AtMega but I have to know where are they written (where they start and finish)

I recognise all the words in that sentence, but put together like that, they don't make a lot of sense.

Can you stop with the pseudo-computer science buzzwords and explain in simple terms what it is you've understood the teacher is telling you to do?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

kf2qd

Since you predefined that there would be 6 - 4k blocks allocated why not just establish the the first or 31st (or whatever) byte of the program is the entry point and then have those addresses hardcoded into your custom loader/scheduler. You would have to have some type of flag configured so you could keep track of whether a given segment has code loaded, or preload each segment with a subroutine return and not worry about it.

your loader would have  something like this

 
  call block1
  call block2
  call block3
  call block4
  call block5
  call block6

block1:
   ret

block2:
  ret

etc.

loaded code would overwrite teh return and the code would execute.
you could also put conditionals before the calls and only call if the bit has been set.

Go Up