Jelajahi Sumber

implementation of ADD, AND, BSUBA, BYTE

DEC, DIV, INC, LDI, MOD, MOV, MUL, NOT, OR, XOR
Wilfried Klaas 6 tahun lalu
induk
melakukan
37edcf1e49
27 mengubah file dengan 335 tambahan dan 617 penghapusan
  1. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/ADD.java
  2. 3 1
      src/main/java/de/mcs/tools/sps/mnemonic/AND.java
  3. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/BSET.java
  4. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/BSUBA.java
  5. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/BYTE.java
  6. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/CSET.java
  7. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/DEC.java
  8. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/DIV.java
  9. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/DSET.java
  10. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/ESET.java
  11. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/FSET.java
  12. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/INC.java
  13. 4 3
      src/main/java/de/mcs/tools/sps/mnemonic/LDI.java
  14. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/MOD.java
  15. 103 0
      src/main/java/de/mcs/tools/sps/mnemonic/MOV.java
  16. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/MUL.java
  17. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/NOT.java
  18. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/OR.java
  19. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/SETB.java
  20. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/SETC.java
  21. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/SETD.java
  22. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/SETE.java
  23. 0 43
      src/main/java/de/mcs/tools/sps/mnemonic/SETF.java
  24. 2 0
      src/main/java/de/mcs/tools/sps/mnemonic/XOR.java
  25. 8 8
      src/test/java/de/mcs/tools/sps/mnemonic/TestLDI.java
  26. 98 0
      src/test/java/de/mcs/tools/sps/mnemonic/TestMOV.java
  27. 97 175
      src/test/java/de/mcs/tools/sps/mnemonic/TestSingleMnemonics.java

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/ADD.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * ADD: A = A + B
+ * 
  * @author wklaa_000
  *
  */

+ 3 - 1
src/main/java/de/mcs/tools/sps/mnemonic/AND.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * AND: A = A & B
+ * 
  * @author wklaa_000
  *
  */
@@ -35,7 +37,7 @@ public class AND extends AbstractMnemonic implements Mnemonic {
 
   @Override
   public int getByte() {
-    return 0x73;
+    return 0x77;
   }
 
 }

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/BSET.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * BSET: setting register B to value of register A
- * 
- * @author wklaa_000
- *
- */
-public class BSET extends AbstractMnemonic implements Mnemonic {
-
-  public BSET(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x51;
-  }
-
-}

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/BSUBA.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * BSUBA: A = B - A
+ * 
  * @author wklaa_000
  *
  */

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/BYTE.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * BYTE: A = A + 16 * B
+ * 
  * @author wklaa_000
  *
  */

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/CSET.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * CSET: setting register C to value of register A
- * 
- * @author wklaa_000
- *
- */
-public class CSET extends AbstractMnemonic implements Mnemonic {
-
-  public CSET(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x52;
-  }
-
-}

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/DEC.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * DEC: A = A - 1
+ * 
  * @author wklaa_000
  *
  */

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/DIV.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * DIV: A = A / B
+ * 
  * @author wklaa_000
  *
  */

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/DSET.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * DSET: setting register D to value of register A
- * 
- * @author wklaa_000
- *
- */
-public class DSET extends AbstractMnemonic implements Mnemonic {
-
-  public DSET(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x53;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/ESET.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * ESET: setting register E to value of register A
- * 
- * @author wklaa_000
- *
- */
-public class ESET extends AbstractMnemonic implements Mnemonic {
-
-  public ESET(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x5D;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/FSET.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * FSET: setting register F to value of register A
- * 
- * @author wklaa_000
- *
- */
-public class FSET extends AbstractMnemonic implements Mnemonic {
-
-  public FSET(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x5E;
-  }
-
-}

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/INC.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * INC: A = A + 1
+ * 
  * @author wklaa_000
  *
  */

+ 4 - 3
src/main/java/de/mcs/tools/sps/mnemonic/SET.java → src/main/java/de/mcs/tools/sps/mnemonic/LDI.java

@@ -27,16 +27,17 @@ import de.mcs.tools.sps.exceptions.IllegalArgument;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
- * SET #x: Setting register A to a static value. x in range 0..15;
+ * LDI #x: Load directly, setting register A to a static value. x in range
+ * 0..15;
  * 
  * @author wklaa_000
  *
  */
-public class SET extends AbstractMnemonic implements Mnemonic {
+public class LDI extends AbstractMnemonic implements Mnemonic {
 
   byte value;
 
-  public SET(String line) throws SyntaxError {
+  public LDI(String line) throws SyntaxError {
     super(line);
     value = 0;
   }

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/MOD.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * MOD: A = A % B
+ * 
  * @author wklaa_000
  *
  */

+ 103 - 0
src/main/java/de/mcs/tools/sps/mnemonic/MOV.java

@@ -0,0 +1,103 @@
+/**
+ * MCS Media Computer Software
+ * Copyright 2018 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: Not.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 25.11.2018 wklaa_000
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.sps.mnemonic;
+
+import org.apache.commons.lang3.StringUtils;
+
+import de.mcs.tools.sps.exceptions.IllegalArgument;
+import de.mcs.tools.sps.exceptions.SyntaxError;
+
+/**
+ * MOV X, Y: setting register X to value of register Y (X=Y)
+ * 
+ * @author wklaa_000
+ *
+ */
+public class MOV extends AbstractMnemonic implements Mnemonic {
+
+  private enum MOVE_VALUE {
+    MOV_BA("A", "B", 0x51), MOV_CA("A", "C", 0x52), MOV_DA("A", "D", 0x53), MOV_EA("A", "E", 0x5d), MOV_FA("A", "F",
+        0x5e), MOV_AB("B", "A",
+            0x61), MOV_AC("C", "A", 0x62), MOV_AD("D", "A", 0x63), MOV_AE("E", "A", 0x6d), MOV_AF("F", "A", 0x6e);
+
+    String source;
+    String dest;
+    int value;
+
+    MOVE_VALUE(String source, String dest, int value) {
+      this.source = source;
+      this.dest = dest;
+      this.value = value;
+    }
+
+  };
+
+  byte output;
+
+  public MOV(String line) throws SyntaxError {
+    super(line);
+    output = 0;
+  }
+
+  @Override
+  public void checkArgument() throws SyntaxError {
+    String argument = getArgument().trim();
+    if (StringUtils.isEmpty(argument)) {
+      throw new SyntaxError(getLineNumber(),
+          String.format("missing arguments for %s.", this.getClass().getSimpleName()));
+    }
+    if (argument.indexOf(",") < 0) {
+      throw new SyntaxError(getLineNumber(),
+          String.format("missing arguments for %s.", this.getClass().getSimpleName()));
+    }
+    int value = 0;
+    argument = argument.replace(",", "");
+    argument = argument.replace(" ", "");
+
+    value = getTime(argument);
+    if (value < 0) {
+      throw new IllegalArgument(getLineNumber(),
+          String.format("argument %s is not in enum for %s.", getArgument(), this.getClass().getSimpleName()));
+    }
+
+    output = (byte) (value & 0xFF);
+  }
+
+  private int getTime(String argument) throws IllegalArgument {
+    try {
+      MOVE_VALUE moveValue = MOVE_VALUE.valueOf(String.format("MOV_%S", argument.trim()));
+      if (moveValue != null) {
+        return moveValue.value;
+      }
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgument(getLineNumber(),
+          String.format("argument %s is not in enum for %s.", getArgument(), this.getClass().getSimpleName()));
+    }
+    return -1;
+  }
+
+  @Override
+  public int getByte() {
+    return output;
+  }
+
+}

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/MUL.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * MUL: A = A * B
+ * 
  * @author wklaa_000
  *
  */

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/NOT.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * NOT: A = !A
+ * 
  * @author wklaa_000
  *
  */

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/OR.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * OR: A = A | B
+ * 
  * @author wklaa_000
  *
  */

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/SETB.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * SETB: copy value of register B to register A
- * 
- * @author wklaa_000
- *
- */
-public class SETB extends AbstractMnemonic implements Mnemonic {
-
-  public SETB(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x61;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/SETC.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * SETC: copy value of register C to register A
- * 
- * @author wklaa_000
- *
- */
-public class SETC extends AbstractMnemonic implements Mnemonic {
-
-  public SETC(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x62;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/SETD.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * SETD: copy value of register D to register A
- * 
- * @author wklaa_000
- *
- */
-public class SETD extends AbstractMnemonic implements Mnemonic {
-
-  public SETD(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x63;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/SETE.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * SETE: copy value of register E to register A
- * 
- * @author wklaa_000
- *
- */
-public class SETE extends AbstractMnemonic implements Mnemonic {
-
-  public SETE(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x6D;
-  }
-
-}

+ 0 - 43
src/main/java/de/mcs/tools/sps/mnemonic/SETF.java

@@ -1,43 +0,0 @@
-/**
- * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
- * Project: SPSEmulator
- * File: Not.java
- * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- */
-package de.mcs.tools.sps.mnemonic;
-
-import de.mcs.tools.sps.exceptions.SyntaxError;
-
-/**
- * SETF: copy value of register F to register A
- * 
- * @author wklaa_000
- *
- */
-public class SETF extends AbstractMnemonic implements Mnemonic {
-
-  public SETF(String line) throws SyntaxError {
-    super(line);
-  }
-
-  @Override
-  public int getByte() {
-    return 0x6E;
-  }
-
-}

+ 2 - 0
src/main/java/de/mcs/tools/sps/mnemonic/XOR.java

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * XOR: A = A ^ B
+ * 
  * @author wklaa_000
  *
  */

+ 8 - 8
src/test/java/de/mcs/tools/sps/mnemonic/TestSET.java → src/test/java/de/mcs/tools/sps/mnemonic/TestLDI.java

@@ -8,32 +8,32 @@ import org.junit.jupiter.api.Test;
 import de.mcs.tools.sps.exceptions.IllegalArgument;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
-class TestSET {
+class TestLDI {
 
   private static final int BYTE_VALUE = 0x40;
-  private final String MNEMONIC = "SET";
+  private final String MNEMONIC = "LDI";
 
   @Test
   void testMnemonic() throws SyntaxError {
-    SET mnemonic = new SET(MNEMONIC + " 0x00");
+    LDI mnemonic = new LDI(MNEMONIC + " 0x00");
     mnemonic.checkArgument();
     assertEquals(BYTE_VALUE, mnemonic.getByte());
 
-    mnemonic = new SET(MNEMONIC + " 0x01");
+    mnemonic = new LDI(MNEMONIC + " 0x01");
     mnemonic.checkArgument();
     assertEquals(BYTE_VALUE + 0x01, mnemonic.getByte());
 
-    mnemonic = new SET(MNEMONIC + " 0x0f");
+    mnemonic = new LDI(MNEMONIC + " 0x0f");
     mnemonic.checkArgument();
     assertEquals(BYTE_VALUE + 0x0f, mnemonic.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SET mnemonic1 = new SET(MNEMONIC);
+      LDI mnemonic1 = new LDI(MNEMONIC);
       mnemonic1.checkArgument();
     });
 
     Assertions.assertThrows(IllegalArgument.class, () -> {
-      SET mnemonic1 = new SET(MNEMONIC + " 0x10");
+      LDI mnemonic1 = new LDI(MNEMONIC + " 0x10");
       mnemonic1.checkArgument();
     });
   }
@@ -41,7 +41,7 @@ class TestSET {
   @Test
   void testMnemonicFactory() throws SyntaxError {
     Mnemonic mnemonic = MnemonicFactory.getMnemonic(MNEMONIC + " 0x00", 0);
-    assertEquals(SET.class, mnemonic.getClass());
+    assertEquals(LDI.class, mnemonic.getClass());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
       MnemonicFactory.getMnemonic(MNEMONIC, 0);

+ 98 - 0
src/test/java/de/mcs/tools/sps/mnemonic/TestMOV.java

@@ -0,0 +1,98 @@
+package de.mcs.tools.sps.mnemonic;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import de.mcs.tools.sps.exceptions.IllegalArgument;
+import de.mcs.tools.sps.exceptions.SyntaxError;
+
+class TestMOV {
+
+  private final String MNEMONIC = "MOV";
+  private final byte BA = 0x51;
+  private final byte CA = 0x52;
+  private final byte DA = 0x53;
+  private final byte EA = 0x5d;
+  private final byte FA = 0x5e;
+
+  private final byte AB = 0x61;
+  private final byte AC = 0x62;
+  private final byte AD = 0x63;
+  private final byte AE = 0x6d;
+  private final byte AF = 0x6e;
+
+  @Test
+  void testMnemonic() throws SyntaxError {
+    MOV mno = new MOV(MNEMONIC + " A, B");
+    mno.checkArgument();
+    assertEquals(AB, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " A, C");
+    mno.checkArgument();
+    assertEquals(AC, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " A, D");
+    mno.checkArgument();
+    assertEquals(AD, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " A, E");
+    mno.checkArgument();
+    assertEquals(AE, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " A, F");
+    mno.checkArgument();
+    assertEquals(AF, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " B, A");
+    mno.checkArgument();
+    assertEquals(BA, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " C, A");
+    mno.checkArgument();
+    assertEquals(CA, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " D, A");
+    mno.checkArgument();
+    assertEquals(DA, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " E, A");
+    mno.checkArgument();
+    assertEquals(EA, mno.getByte());
+
+    mno = new MOV(MNEMONIC + " F, A");
+    mno.checkArgument();
+    assertEquals(FA, mno.getByte());
+
+    Assertions.assertThrows(SyntaxError.class, () -> {
+      DIN mno1 = new DIN(MNEMONIC + " 0x05");
+      mno1.checkArgument();
+    });
+
+    Assertions.assertThrows(IllegalArgument.class, () -> {
+      DIN mno1 = new DIN(MNEMONIC + " 0x10");
+      mno1.checkArgument();
+    });
+
+    Assertions.assertThrows(IllegalArgument.class, () -> {
+      DIN mno1 = new DIN(MNEMONIC + " A, G");
+      mno1.checkArgument();
+    });
+  }
+
+  @Test
+  void testMnemonicFactory() throws SyntaxError {
+    Mnemonic mnemonic = MnemonicFactory.getMnemonic(MNEMONIC + " A, B", 0);
+    assertEquals(MOV.class, mnemonic.getClass());
+
+    Assertions.assertThrows(SyntaxError.class, () -> {
+      MnemonicFactory.getMnemonic(MNEMONIC + " 0x00", 0);
+    });
+
+    Assertions.assertThrows(SyntaxError.class, () -> {
+      MnemonicFactory.getMnemonic(MNEMONIC + " AB", 0);
+    });
+
+  }
+}

+ 97 - 175
src/test/java/de/mcs/tools/sps/mnemonic/TestSingleMnemonics.java

@@ -31,255 +31,168 @@ class TestSingleMnemonics {
   }
 
   @Test
-  void testBSET() throws SyntaxError {
-    BSET mno = new BSET("BSET");
-    assertEquals(0x51, mno.getByte());
+  void testPUSH() throws SyntaxError {
+    PUSH mno = new PUSH("PUSH");
+    assertEquals(0x5f, mno.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      BSET mno1 = new BSET("BSET akfhaskh");
+      PUSH mno1 = new PUSH("PUSH akfhaskh");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      BSET mno1 = new BSET("BSET 12");
+      PUSH mno1 = new PUSH("PUSH 12");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      BSET mno1 = new BSET("BSET :label");
+      PUSH mno1 = new PUSH("PUSH :label");
       mno1.checkArgument();
     });
   }
 
   @Test
-  void testSETB() throws SyntaxError {
-    SETB mno = new SETB("SETB");
-    assertEquals(0x61, mno.getByte());
+  void testPOP() throws SyntaxError {
+    POP mno = new POP("POP");
+    assertEquals(0x6f, mno.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETB mno1 = new SETB("SETB akfhaskh");
+      POP mno1 = new POP("POP akfhaskh");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETB mno1 = new SETB("SETB 12");
+      POP mno1 = new POP("POP 12");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETB mno1 = new SETB("SETB :label");
+      POP mno1 = new POP("POP :label");
       mno1.checkArgument();
     });
   }
 
   @Test
-  void testCSET() throws SyntaxError {
-    CSET mno = new CSET("CSET");
-    assertEquals(0x52, mno.getByte());
+  void testINC() throws SyntaxError {
+    INC mno = new INC("INC");
+    assertEquals(0x71, mno.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      CSET mno1 = new CSET("CSET akfhaskh");
+      INC mno1 = new INC("INC akfhaskh");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      CSET mno1 = new CSET("CSET 12");
+      INC mno1 = new INC("INC 12");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      CSET mno1 = new CSET("CSET :label");
+      INC mno1 = new INC("INC :label");
       mno1.checkArgument();
     });
   }
 
   @Test
-  void testSETC() throws SyntaxError {
-    SETC mno = new SETC("SETC");
-    assertEquals(0x62, mno.getByte());
+  void testDEC() throws SyntaxError {
+    DEC mno = new DEC("DEC");
+    assertEquals(0x72, mno.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETC mno1 = new SETC("SETC akfhaskh");
+      DEC mno1 = new DEC("DEC akfhaskh");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETC mno1 = new SETC("SETC 12");
+      DEC mno1 = new DEC("DEC 12");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      SETC mno1 = new SETC("SETC :label");
+      DEC mno1 = new DEC("DEC :label");
       mno1.checkArgument();
     });
   }
 
   @Test
-  void testDSET() throws SyntaxError {
-    DSET mno = new DSET("DSET");
-    assertEquals(0x53, mno.getByte());
+  void testADD() throws SyntaxError {
+    ADD mno = new ADD("ADD");
+    assertEquals(0x73, mno.getByte());
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      DSET mno1 = new DSET("DSET akfhaskh");
+      ADD mno1 = new ADD("DEC akfhaskh");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      DSET mno1 = new DSET("DSET 12");
+      ADD mno1 = new ADD("ADD 12");
       mno1.checkArgument();
     });
 
     Assertions.assertThrows(SyntaxError.class, () -> {
-      DSET mno1 = new DSET("DSET :label");
+      ADD mno1 = new ADD("ADD :label");
       mno1.checkArgument();
     });
   }
 
   @Test
-  void testSETD() throws SyntaxError {
-    SETD mno = new SETD("SETD");
-    assertEquals(0x63, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETD mno1 = new SETD("SETD akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETD mno1 = new SETD("SETD 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETD mno1 = new SETD("SETD :label");
-      mno1.checkArgument();
-    });
+  void testSUB() throws SyntaxError {
+    SUB mno = new SUB("SUB");
+    assertEquals(0x74, mno.getByte());
   }
 
   @Test
-  void testESET() throws SyntaxError {
-    ESET mno = new ESET("ESET");
-    assertEquals(0x5d, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      ESET mno1 = new ESET("ESET akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      ESET mno1 = new ESET("ESET 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      ESET mno1 = new ESET("ESET :label");
-      mno1.checkArgument();
-    });
+  void testMUL() throws SyntaxError {
+    MUL mno = new MUL("MUL");
+    assertEquals(0x75, mno.getByte());
   }
 
   @Test
-  void testSETE() throws SyntaxError {
-    SETE mno = new SETE("SETE");
-    assertEquals(0x6D, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETE mno1 = new SETE("SETE akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETE mno1 = new SETE("SETE 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETE mno1 = new SETE("SETE :label");
-      mno1.checkArgument();
-    });
+  void testDIV() throws SyntaxError {
+    DIV mno = new DIV("DIV");
+    assertEquals(0x76, mno.getByte());
   }
 
   @Test
-  void testFSET() throws SyntaxError {
-    FSET mno = new FSET("FSET");
-    assertEquals(0x5e, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      FSET mno1 = new FSET("FSET akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      FSET mno1 = new FSET("FSET 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      FSET mno1 = new FSET("FSET :label");
-      mno1.checkArgument();
-    });
+  void testAND() throws SyntaxError {
+    AND mno = new AND("AND");
+    assertEquals(0x77, mno.getByte());
   }
 
   @Test
-  void testSETF() throws SyntaxError {
-    SETF mno = new SETF("SETF");
-    assertEquals(0x6E, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETF mno1 = new SETF("SETF akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETF mno1 = new SETF("SETF 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      SETF mno1 = new SETF("SETF :label");
-      mno1.checkArgument();
-    });
+  void testOR() throws SyntaxError {
+    OR mno = new OR("OR");
+    assertEquals(0x78, mno.getByte());
   }
 
   @Test
-  void testPUSH() throws SyntaxError {
-    PUSH mno = new PUSH("PUSH");
-    assertEquals(0x5f, mno.getByte());
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      PUSH mno1 = new PUSH("PUSH akfhaskh");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      PUSH mno1 = new PUSH("PUSH 12");
-      mno1.checkArgument();
-    });
-
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      PUSH mno1 = new PUSH("PUSH :label");
-      mno1.checkArgument();
-    });
+  void testXOR() throws SyntaxError {
+    XOR mno = new XOR("XOR");
+    assertEquals(0x79, mno.getByte());
   }
 
   @Test
-  void testPOP() throws SyntaxError {
-    POP mno = new POP("POP");
-    assertEquals(0x6f, mno.getByte());
+  void testNOT() throws SyntaxError {
+    NOT mno = new NOT("NOT");
+    assertEquals(0x7a, mno.getByte());
+  }
 
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      POP mno1 = new POP("POP akfhaskh");
-      mno1.checkArgument();
-    });
+  @Test
+  void testMOD() throws SyntaxError {
+    MOD mno = new MOD("MOD");
+    assertEquals(0x7b, mno.getByte());
+  }
 
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      POP mno1 = new POP("POP 12");
-      mno1.checkArgument();
-    });
+  @Test
+  void testBYTE() throws SyntaxError {
+    BYTE mno = new BYTE("BYTE");
+    assertEquals(0x7c, mno.getByte());
+  }
 
-    Assertions.assertThrows(SyntaxError.class, () -> {
-      POP mno1 = new POP("POP :label");
-      mno1.checkArgument();
-    });
+  @Test
+  void testBSUBA() throws SyntaxError {
+    BSUBA mno = new BSUBA("BSUBA");
+    assertEquals(0x7d, mno.getByte());
   }
 
   @Test
@@ -287,37 +200,46 @@ class TestSingleMnemonics {
     Mnemonic mnemonic = MnemonicFactory.getMnemonic("SWAP", 0);
     assertEquals(SWAP.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("BSET", 0);
-    assertEquals(BSET.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("PUSH", 0);
+    assertEquals(PUSH.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("CSET", 0);
-    assertEquals(CSET.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("INC", 0);
+    assertEquals(INC.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("DSET", 0);
-    assertEquals(DSET.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("DEC", 0);
+    assertEquals(DEC.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("ESET", 0);
-    assertEquals(ESET.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("ADD", 0);
+    assertEquals(ADD.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("FSET", 0);
-    assertEquals(FSET.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("SUB", 0);
+    assertEquals(SUB.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("PUSH", 0);
-    assertEquals(PUSH.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("MUL", 0);
+    assertEquals(MUL.class, mnemonic.getClass());
+
+    mnemonic = MnemonicFactory.getMnemonic("DIV", 0);
+    assertEquals(DIV.class, mnemonic.getClass());
+
+    mnemonic = MnemonicFactory.getMnemonic("AND", 0);
+    assertEquals(AND.class, mnemonic.getClass());
+
+    mnemonic = MnemonicFactory.getMnemonic("OR", 0);
+    assertEquals(OR.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("SETB", 0);
-    assertEquals(SETB.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("XOR", 0);
+    assertEquals(XOR.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("SETC", 0);
-    assertEquals(SETC.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("NOT", 0);
+    assertEquals(NOT.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("SETD", 0);
-    assertEquals(SETD.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("MOD", 0);
+    assertEquals(MOD.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("SETE", 0);
-    assertEquals(SETE.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("BYTE", 0);
+    assertEquals(BYTE.class, mnemonic.getClass());
 
-    mnemonic = MnemonicFactory.getMnemonic("SETF", 0);
-    assertEquals(SETF.class, mnemonic.getClass());
+    mnemonic = MnemonicFactory.getMnemonic("BSUBA", 0);
+    assertEquals(BSUBA.class, mnemonic.getClass());
   }
 }