protected Register getRegister(ProgramLocationActionContext context) {
		Program program = context.getProgram();
		ProgramLocation location = context.getLocation();
		if (location instanceof OperandFieldLocation) {
			OperandFieldLocation opLoc = (OperandFieldLocation) location;
			CodeUnit cu = program.getListing().getCodeUnitAt(opLoc.getAddress());
			if (cu instanceof Instruction) {
				Instruction inst = (Instruction) cu;
				Object[] opObjs = inst.getOpObjects(opLoc.getOperandIndex());
				for (Object object : opObjs) {
					if (object instanceof Register) {
						return (Register) object;
					}
				}
			}
		}
		return null;
	}
Shows the registers available in a program along with any values that are set.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/register/RegisterPlugin.java