public void set(int addr, char val) {
    if (addr < 65536)
      ram[addr & 0xFFFF] = val;
    else if (addr < 65544) {
//    	if (disassemble)
//    	{
//    		System.out.println("register[" + (int)(addr & 0x7) + "] = " + (int)val);
//    	}
      registers[addr & 0x7] = val;
    } else if (addr < 131072) {
      if (addr == 65544)
        sp = val;
      else if (addr == 65545)
        pc = val;
      else if (addr == 65552)
        ex = val;
      else
        throw new IllegalStateException("Illegal address " + Integer.toHexString(addr) + "! How did you manage that!?"); 
    }
  }