// Path: src/main/java/com/kasirgalabs/etumulator/util/BaseDispatcher.java
// public class BaseDispatcher implements Dispatcher {
//     private final List<Observer> observers;
// 
//     public BaseDispatcher() {
//         observers = new ArrayList<>(10);
//     }
// 
//     @Override
//     public void addObserver(Observer observer) {
//         observers.add(observer);
//     }
// 
//     @Override
//     public void notifyObservers(Class<?> clazz, Object arg) {
//         for(int i = 0; i < observers.size(); i++) {
//             observers.get(i).update(clazz, arg);
//         }
//     }
// 
//     @Override
//     public void notifyObservers(Class<?> clazz) {
//         notifyObservers(clazz, null);
//     }
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Dispatcher.java
// public interface Dispatcher {
//     void addObserver(Observer observer);
// 
//     void notifyObservers(Class<?> clazz, Object arg);
// 
//     void notifyObservers(Class<?> clazz);
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Observable.java
// public interface Observable {
//     void addObserver(Observer observer);
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Observer.java
// public interface Observer {
//     void update(Class<?> clazz, Object arg);
// }


import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.kasirgalabs.etumulator.util.BaseDispatcher;
import com.kasirgalabs.etumulator.util.Dispatcher;
import com.kasirgalabs.etumulator.util.Observable;
import com.kasirgalabs.etumulator.util.Observer;
package com.kasirgalabs.etumulator.processor;


/**
 * A link register is a special-purpose register which holds the address to return to when a
 * function call completes. When a BL instruction performs a subroutine call, LR is set to the
 * subroutine return address. To perform a subroutine return, copy LR back to the program counter.
 * This is done in the following way, after entering the subroutine with a BL instruction:<br>
 * On subroutine entry, store LR to the stack with an instruction of the form: PUSH {LR} and use
 * a matching instruction to return: POP {PC}
 * <p>
 * This class represents an observable object. After a state change on LR value, all of it's
 * observers will be notified through default {@link BaseDispatcher} or the Dispatcher initialized
 * during construction.
 *
 * @author Görkem Mülayim
 * @see PC
 */
@Singleton
public class LR implements Observable {
    private int lr;
    private final Dispatcher dispatcher;

    /**
     * Construct a LR with {@link BaseDispatcher}.
     *
     * @see BaseDispatcher
     */
    public LR() {
// Path: src/main/java/com/kasirgalabs/etumulator/util/BaseDispatcher.java
// public class BaseDispatcher implements Dispatcher {
//     private final List<Observer> observers;
// 
//     public BaseDispatcher() {
//         observers = new ArrayList<>(10);
//     }
// 
//     @Override
//     public void addObserver(Observer observer) {
//         observers.add(observer);
//     }
// 
//     @Override
//     public void notifyObservers(Class<?> clazz, Object arg) {
//         for(int i = 0; i < observers.size(); i++) {
//             observers.get(i).update(clazz, arg);
//         }
//     }
// 
//     @Override
//     public void notifyObservers(Class<?> clazz) {
//         notifyObservers(clazz, null);
//     }
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Dispatcher.java
// public interface Dispatcher {
//     void addObserver(Observer observer);
// 
//     void notifyObservers(Class<?> clazz, Object arg);
// 
//     void notifyObservers(Class<?> clazz);
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Observable.java
// public interface Observable {
//     void addObserver(Observer observer);
// }
// 
// Path: src/main/java/com/kasirgalabs/etumulator/util/Observer.java
// public interface Observer {
//     void update(Class<?> clazz, Object arg);
// }


// Path: src/main/java/com/kasirgalabs/etumulator/processor/LR.java
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.kasirgalabs.etumulator.util.BaseDispatcher;
import com.kasirgalabs.etumulator.util.Dispatcher;
import com.kasirgalabs.etumulator.util.Observable;
import com.kasirgalabs.etumulator.util.Observer;

package com.kasirgalabs.etumulator.processor;


/**
 * A link register is a special-purpose register which holds the address to return to when a
 * function call completes. When a BL instruction performs a subroutine call, LR is set to the
 * subroutine return address. To perform a subroutine return, copy LR back to the program counter.
 * This is done in the following way, after entering the subroutine with a BL instruction:<br>
 * On subroutine entry, store LR to the stack with an instruction of the form: PUSH {LR} and use
 * a matching instruction to return: POP {PC}
 * <p>
 * This class represents an observable object. After a state change on LR value, all of it's
 * observers will be notified through default {@link BaseDispatcher} or the Dispatcher initialized
 * during construction.
 *
 * @author Görkem Mülayim
 * @see PC
 */
@Singleton
public class LR implements Observable {
    private int lr;
    private final Dispatcher dispatcher;

    /**
     * Construct a LR with {@link BaseDispatcher}.
     *
     * @see BaseDispatcher
     */
    public LR() {
        dispatcher = new BaseDispatcher();