1 package net.mograsim.logic.model.am2900.machine.registers;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.HashSet;
10 import net.mograsim.machine.StandardRegister;
12 public class NumberedRegister extends StandardRegister
14 public static final List<NumberedRegister> instancesCorrectOrder;
18 List<NumberedRegister> instancesCorrectOrderModifiable = new ArrayList<>();
19 for (int i = 0; i < 16; i++)
20 instancesCorrectOrderModifiable.add(new NumberedRegister(i));
21 instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable);
24 private final int index;
25 private final String indexBitstring;
27 private NumberedRegister(int i)
29 super("R" + i, new HashSet<>(Arrays.asList(new String[] { "R" + i, "Register #" + i, "Register " + i })), 16, new HashMap<>());
32 StringBuilder sb = new StringBuilder();
33 sb.append((index & 0b1000) != 0 ? '1' : '0');
34 sb.append((index & 0b0100) != 0 ? '1' : '0');
35 sb.append((index & 0b0010) != 0 ? '1' : '0');
36 sb.append((index & 0b0001) != 0 ? '1' : '0');
37 this.indexBitstring = sb.toString();
45 public String getIndexAsBitstring()
47 return indexBitstring;