public int write(short address, short data) {
		int offset = 0;
		for (int i = 0; i < offsetBits; i++) {
			offset |= address & (1 << i);
		}
		address >>= offsetBits;
		int index = 0;
		for (int i = 0; i < indexBits; i++) {
			index |= address & (1 << i);
		}
		address >>= indexBits;
		int tag = 0;
		for (int i = 0; i < tagBits; i++) {
			tag |= address & (1 << i);
		}
		for (int i = 0; i < cacheMemory[index].length; i++) {
			if (cacheMemory[index][i].valid && cacheMemory[index][i].tag == tag) {
				hits++;
				if (wpHit == write_through) {
					cacheMemory[index][i].data[offset + 1] = (byte) data;
					data >>= 8;
					cacheMemory[index][i].data[offset] = (byte) data;
					int stall = ancestor.write(address, data);
					return stall += accessTime;
				} else {
					mainMemory.write(address, data);
					return mainMemory.accessTime;
				}
			}
		}
		misses++;
		if (wpMiss == write_allocate) {
			Random rand = new Random();
			int r = rand.nextInt(m);
			cacheMemory[index][r].data = ancestor.getBlock(address, l);
			return accessTime;
		} else {
			mainMemory.write(address, data);
			return mainMemory.accessTime;
		}
	}