boolean updateReference(Reference editRef, CodeUnit fromCodeUnit, Register reg,
			RefType refType) {

		Program p = fromCodeUnit.getProgram();

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

		CompoundCmd<Program> cmd = new CompoundCmd<>("Update Register Reference");
		cmd.add(new RemoveReferenceCmd(editRef));
		cmd.add(new AddRegisterRefCmd(fromAddr, editRef.getOperandIndex(), 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