I wrote a program using c language., In this program, I was able to be accessed by a pointer to a specific address and opcode can print it.I've used this method to write the self modifying code.I did this in 8086 architecture. I want it running on a microcontroller PIC18F2550.I am using a Mplab IDE 8.92 with Mplab C18 3.46.I've never done this before with microcontroller. Unlike 8086 Here I do not have access to the opcode!The pointer is the address of the opcode. However, the return value is 0X00!This is a code sample
#include <stdio.h>
#include <stdlib.h>
void fsub(void){
int a,b;
a=3;b=5;
a-=b;
printf("a-b=%d\n",a);
}
void fadd(void)
{
int a,b;
a=3;b=5;
a+=b;
printf("a+b=%d\n",a);
}
void retadd(void);
void main()
{
int i;
unsigned char *instSub,*instAdd;
unsigned char instructionSub[2];
void *retadd_addr=(void*)retadd;
retadd();
instSub=(unsigned char*)retadd_addr;
instAdd=(unsigned char*)retadd_addr+2;
printf("%x\n", *instSub);
printf("%x\n", *instAdd);
while(1);
}
void retadd(void)
{
fsub();
fadd();
}
![picture from mplab]this picture show Values1