public Instruction createCodeUnit(Address address, InstructionPrototype prototype,
			MemBuffer memBuf, ProcessorContextView context, int length)
			throws CodeUnitInsertionException {

		lock.acquire();
		creatingInstruction = true;
		try {
			int forcedLengthOverride = InstructionDB.checkLengthOverride(length, prototype);
			if (length == 0) {
				length = prototype.getLength();
			}
			Address endAddr = address.addNoWrap(length - 1);
			checkValidAddressRange(address, endAddr);

			InstructionDB inst = addInstruction(address, endAddr, prototype, memBuf, context);
			if (forcedLengthOverride != 0) {
				inst.doSetLengthOverride(forcedLengthOverride);
			}

			// fire event
			program.setChanged(ProgramEvent.CODE_ADDED, address, endAddr, null, inst);

			return inst;
		}
		catch (AddressOverflowException e) {
			throw new CodeUnitInsertionException("Code unit would extend beyond Address space");
		}
		catch (IOException e) {
			program.dbError(e);
		}
		finally {
			creatingInstruction = false;
			lock.release();
		}
		return null;
	}
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