private InstructionDB addInstruction(Address address, Address endAddr,
			InstructionPrototype prototype, MemBuffer memBuf, ProcessorContextView context)
			throws IOException {

		int protoID = protoMgr.getID(prototype, memBuf, context);
		prototype = protoMgr.getPrototype(protoID);

		Register contextReg = contextMgr.getBaseContextRegister();
		if (contextReg != Register.NO_CONTEXT) {
			RegisterValue contextValue = context.getRegisterValue(contextReg);
			if (contextValue != null && contextValue.hasAnyValue()) {
				saveInstructionContext(address, endAddr, contextValue);
			}
		}

		// create new instruction record
		long addr = addrMap.getKey(address, true);
		byte flags = 0;
		if (redisassemblyMode) {
			Byte byteFlags = redisassmblyFlags.get(addr);
			flags = (byteFlags == null) ? 0 : byteFlags;
		}
		instAdapter.createInstruction(addr, protoID, flags);

		cache.delete(addrMap.getKeyRanges(address, endAddr, false));

		// create new InstructionDB object and add to the cache (conflicts assumed to have been removed)
		InstructionDB inst = new InstructionDB(this, cache, address, addr, prototype, flags);

		addReferencesForInstruction(inst);
		return inst;
	}
Creates an instruction at the specified address.

@param address start address of instruction
@param prototype  instruction definition object
@param memBuf the MemBuffer to use to get the bytes from memory
@param context object that has the state of all the registers.
@param length instruction byte-length (must be in the range 0..prototype.getLength()).
If smaller than the prototype length it must have a value no greater than 7, otherwise
an error will be thrown.  A value of 0 or greater-than-or-equal the prototype length
will be ignored and not impose and override length.  The length value must be a multiple 
of the {@link Language#getInstructionAlignment() instruction alignment} .
@return the newly created instruction.  
@throws CodeUnitInsertionException thrown if the new Instruction would overlap and 
existing {@link CodeUnit} or the specified {@code length} is unsupported.
@throws IllegalArgumentException if a negative {@code length} is specified.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java