boolean addReference(CodeUnit fromCodeUnit, int opIndex, Register reg, RefType refType) {

		if (!confirmPossibleReferenceRemoval(fromCodeUnit, opIndex, null)) {
			return false;
		}

		Program p = fromCodeUnit.getProgram();

		Address fromAddr = fromCodeUnit.getMinAddress();
		Function f = p.getFunctionManager().getFunctionContaining(fromAddr);
		if (f == null) {
			return false;
		}

		AddRegisterRefCmd cmd =
			new AddRegisterRefCmd(fromAddr, opIndex, reg, refType, SourceType.USER_DEFINED);
		return tool.execute(cmd, p);
	}
Add memory reference

@param fromCodeUnit
@param opIndex
@param toAddr
@param isOffsetRef
@param offset
@param refType
@return true if add was successful
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ReferencesPlugin.java