Program Counter (PC)

//making 6 partitions of the memory of 4k-size each

Which chip are you using? That's a heck of a lot of RAM.

Here's some excerpts from a monitor program I wrote a while back, it was an ISR but I think NAKED works with functions as well. You probably don't need to save all the regs.

ISR (WDT_vect, ISR_NAKED) {
  
  /////////////////////////////////////////////
  // DIY prologue so I know exactly where the
  // program counter and working registers are
  asm (
    "push r0\n"
    "in r0,0x3f\n"
    "push r0\npush r1\npush r2\npush r3\npush r4\n"
    "push r5\npush r6\npush r7\npush r8\npush r9\n"
    "push r10\npush r11\npush r12\npush r13\npush r14\n"
    "push r15\npush r16\npush r17\npush r18\npush r19\n"
    "push r20\npush r21\npush r22\npush r23\npush r24\n"
    "push r25\npush r26\npush r27\npush r28\npush r29\n"
    "push r30\npush r31\n"
  );  // 33 bytes on the stack
....

    case  CMD_PC:
       address = (byte*)(SPL + (SPH << 8));
       address += 35; // skip 33 preamble bytes, 
                      // +1 to allow for SP post decrement
                      // +1 because it seems to work ??
       resp_lo = *(address+1);
       resp_hi = *address;
       break;
....

This was used to return the PC but could also be used to change it.

I gather the "tasks" will be located in that memory you allocated, in which case you can use the address of the base of each block if I understand you correctly.


Rob