   Serial.println("");
   Serial.flush();
 
-  return ret ^ funcid;
+  return ret ^ function;
 }
 
 


#define UNUSED __attribute__((unused))

#define MEM_SIZE 1*1024 //bytes of RAM allocated to the VM
#define PROG_LENGTH 128 //bytes of instruction read by the VM
#define PROG_OFFSET 0 //address of program in EEPROM
#define PROG_START 0 //address of first instruction (relative to PROG_OFFSET
#define BAUDRATE 9600 //UART baudrate
#define VERBOSE false //verbose mode

boolean stop = false;
byte memory[MEM_SIZE];

//put in seperate namespace to prevent Arduino IDE from preprocessing it; Arduino preprocessor is ST00PID
namespace no {
  struct embedvm_s vm = {
    0xffff, 0, 0, NULL,
    &mem_read, &mem_write, &call_user
  };
}

void setup()
{
  Serial.begin(BAUDRATE);
  for(int addr = 0; addr < PROG_LENGTH; addr++)
    memory[addr] = EEPROM.read(addr + PROG_OFFSET);
  embedvm_interrupt(&no::vm, PROG_START);
}

void loop()

}


static int16_t memoryRead(uint16_t address, bool is16bit, void *ctx UNUSED)
{
  if (is16bit)
    return (memory[address] << 8) | memory[address+1];
  return memory[address];
}

static void memoryWrite(uint16_t address, int16_t value, bool is16bit, void *ctx UNUSED)
{
  if (is16bit) {
    memory[address] = value >> 8;
    memory[address+1] = value;
  } 
  else
    memory[address] = value;
}

static int16_t callUserFunction(uint8_t function, uint8_t argc, int16_t *argv, void *ctx UNUSED)
{
  int16_t ret = 0;
  int i;

  if (function == 0) {
    stop = true;
    Serial.println("Called user function 0 => stop.");
    Serial.flush();
    return ret;
  }

  Serial.print("Called user function " + String(function) + " with " + String(argc) + " args:");

  for (i = 0; i < argc; i++) {
    Serial.print(" " + argv[i]);
