Jelajahi Sumber

implemeting PUSH

Wilfried Klaas 6 tahun lalu
induk
melakukan
c5807fe153

+ 6 - 0
SimpleServo.tps

@@ -15,6 +15,12 @@ CSET
 DSET
 ESET
 FSET
+DOUT
+DOUT 3
+PWM 2
+SRV 0x01
 RJMP 0x06
 RJMP :loop
 JMP 0x08 ;this will cause an syntax error
+PUSH
+POP

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

@@ -24,6 +24,8 @@ package de.mcs.tools.sps.mnemonic;
 import de.mcs.tools.sps.exceptions.SyntaxError;
 
 /**
+ * PUSH: Push register A on stack.
+ * 
  * @author wklaa_000
  *
  */

+ 24 - 0
src/test/java/de/mcs/tools/sps/mnemonic/TestSingleMnemonics.java

@@ -135,6 +135,27 @@ class TestSingleMnemonics {
     });
   }
 
+  @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();
+    });
+  }
+
   @Test
   void testMnemonicFactory() throws SyntaxError {
     Mnemonic mnemonic = MnemonicFactory.getMnemonic("SWAP", 0);
@@ -154,5 +175,8 @@ class TestSingleMnemonics {
 
     mnemonic = MnemonicFactory.getMnemonic("FSET", 0);
     assertEquals(FSET.class, mnemonic.getClass());
+
+    mnemonic = MnemonicFactory.getMnemonic("PUSH", 0);
+    assertEquals(PUSH.class, mnemonic.getClass());
   }
 }