
/////////// the jumptable

void dlltab(void) __naked {
__asm
  .area DLLTAB (ABS)
  .org  0HFF80           ;set location to absolute address
__endasm;
}

void T_function1(void) __naked {
__asm
  ljmp   _N_function1    ;this is patched; was: ljmp  O_function1
__endasm;
}

void T_function2(void) __naked {
__asm
  ljmp   O_function2
__endasm;
}

////////////// the patch area

void N_dummyfunction(void) __naked {
__asm
  .area PATCH (ABS)
  .org  0H1000            // we know from the mapfile that this area is empty
__endasm;
}

bit N_function1(char a) {
//data at 0x0002 char a;  // r2 - this is nasty but works; 
                          //but the passing via 1 parameter 
                          //works too and is nicer
data at 0x000B char b;    // we know the absolute address from the mapfile
  if (a < b) return(1); else return(0);
}



///////////// the original code


void dummyfunction(void) __naked {
__asm
  .area CSEG    (CODE)
__endasm;
}


#include <8051.h>
#include <stdio.h>


char c;

bit function1(char a, char b) {
__asm
  ljmp  _T_function1
O_function1:
__endasm;
  if (a == b) return(1); else return(0);
}


char function2(char a) {
__asm
  ljmp  _T_function2
O_function2:
__endasm;
  return(a*2);
}

void main(void) {
  c = 5;
  printf("%d", function2(function1(c,3)));

}
