diff --git a/HelloWorld.java b/HelloWorld.java deleted file mode 100644 index 198d438..0000000 --- a/HelloWorld.java +++ /dev/null @@ -1,14 +0,0 @@ -import commands.Command; -import decoder.CommandDecoder; - -import java.util.ArrayList; - -class HelloWorld { - public static void main(String[] args) { - //System.out.println(Parser.Parser.parser("TPicSim2.LST")); - ArrayList program = new ArrayList<>(); - int input1 = 0x3EFF; - program.add(CommandDecoder.decode(input1)); - program.get(0).execute(); - } -} \ No newline at end of file diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java new file mode 100644 index 0000000..621c939 --- /dev/null +++ b/de/darkress/pic16f84sim/Main.java @@ -0,0 +1,33 @@ +package de.darkress.pic16f84sim; + +import de.darkress.pic16f84sim.commands.Command; +import de.darkress.pic16f84sim.decoder.CommandDecoder; +import de.darkress.pic16f84sim.registers.Memory; +import de.darkress.pic16f84sim.registers.Stack; + +import java.util.ArrayList; + +class Main +{ + public static void main(String[] args) { + /* + ArrayList program = new ArrayList<>(); + int input1 = 0x3EFF; + program.add(CommandDecoder.decode(input1)); + program.get(0).execute(); + */ + + for(int i = 0; i < 8; i++) + { + Stack.push(i); + } + + for(int i = 0; i < 16; i++) + { + System.out.println(Stack.peek()); + Stack.pop(); + } + + + } +} \ No newline at end of file diff --git a/commands/Addlw.java b/de/darkress/pic16f84sim/commands/Addlw.java similarity index 82% rename from commands/Addlw.java rename to de/darkress/pic16f84sim/commands/Addlw.java index d74a7a7..b14e93d 100644 --- a/commands/Addlw.java +++ b/de/darkress/pic16f84sim/commands/Addlw.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class Addlw extends CommandUtils implements Command { diff --git a/commands/Andlw.java b/de/darkress/pic16f84sim/commands/Andlw.java similarity index 79% rename from commands/Andlw.java rename to de/darkress/pic16f84sim/commands/Andlw.java index 8c98b6e..94ff44d 100644 --- a/commands/Andlw.java +++ b/de/darkress/pic16f84sim/commands/Andlw.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class Andlw extends CommandUtils implements Command { diff --git a/commands/Command.java b/de/darkress/pic16f84sim/commands/Command.java similarity index 54% rename from commands/Command.java rename to de/darkress/pic16f84sim/commands/Command.java index a5fab5d..b087873 100644 --- a/commands/Command.java +++ b/de/darkress/pic16f84sim/commands/Command.java @@ -1,4 +1,4 @@ -package commands; +package de.darkress.pic16f84sim.commands; public interface Command { diff --git a/commands/CommandUtils.java b/de/darkress/pic16f84sim/commands/CommandUtils.java similarity index 87% rename from commands/CommandUtils.java rename to de/darkress/pic16f84sim/commands/CommandUtils.java index 645b1fc..62ea17e 100644 --- a/commands/CommandUtils.java +++ b/de/darkress/pic16f84sim/commands/CommandUtils.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class CommandUtils { diff --git a/commands/Iorlw.java b/de/darkress/pic16f84sim/commands/Iorlw.java similarity index 79% rename from commands/Iorlw.java rename to de/darkress/pic16f84sim/commands/Iorlw.java index 2522319..3ac7fd4 100644 --- a/commands/Iorlw.java +++ b/de/darkress/pic16f84sim/commands/Iorlw.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class Iorlw extends CommandUtils implements Command { diff --git a/commands/Movlw.java b/de/darkress/pic16f84sim/commands/Movlw.java similarity index 74% rename from commands/Movlw.java rename to de/darkress/pic16f84sim/commands/Movlw.java index 38233cd..7f381f6 100644 --- a/commands/Movlw.java +++ b/de/darkress/pic16f84sim/commands/Movlw.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class Movlw extends CommandUtils implements Command { diff --git a/commands/Sublw.java b/de/darkress/pic16f84sim/commands/Sublw.java similarity index 90% rename from commands/Sublw.java rename to de/darkress/pic16f84sim/commands/Sublw.java index f229fe5..247cdf4 100644 --- a/commands/Sublw.java +++ b/de/darkress/pic16f84sim/commands/Sublw.java @@ -1,6 +1,6 @@ -package commands; +package de.darkress.pic16f84sim.commands; -import registers.Memory; +import de.darkress.pic16f84sim.registers.Memory; public class Sublw extends CommandUtils implements Command { diff --git a/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java similarity index 97% rename from decoder/CommandDecoder.java rename to de/darkress/pic16f84sim/decoder/CommandDecoder.java index 0f39c6a..9c6d79a 100644 --- a/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -1,6 +1,6 @@ -package decoder; +package de.darkress.pic16f84sim.decoder; -import commands.*; +import de.darkress.pic16f84sim.commands.*; public class CommandDecoder { diff --git a/parser/Parser.java b/de/darkress/pic16f84sim/parser/Parser.java similarity index 96% rename from parser/Parser.java rename to de/darkress/pic16f84sim/parser/Parser.java index a44f1fc..11ef336 100644 --- a/parser/Parser.java +++ b/de/darkress/pic16f84sim/parser/Parser.java @@ -1,4 +1,4 @@ -package parser; +package de.darkress.pic16f84sim.parser; import java.io.File; import java.io.FileNotFoundException; diff --git a/registers/Memory.java b/de/darkress/pic16f84sim/registers/Memory.java similarity index 95% rename from registers/Memory.java rename to de/darkress/pic16f84sim/registers/Memory.java index 010ca75..b3f6c54 100644 --- a/registers/Memory.java +++ b/de/darkress/pic16f84sim/registers/Memory.java @@ -1,4 +1,4 @@ -package registers; +package de.darkress.pic16f84sim.registers; import java.util.Arrays; @@ -12,7 +12,7 @@ public class Memory public static int getRegister(int address) { - if(address + 128 > 255) //Guard statement to check for early errors in command decoder or implementation + if(address + 128 > 255) //Guard statement to check for early errors in command de.darkress.pic16f84sim.decoder or implementation { System.err.println("Guard statement triggered. The address must be 7Bit long and can therefore not exceed" + " 127"); @@ -35,7 +35,7 @@ public class Memory public static void setRegister(int address, int data) { - if(address + 128 > 255) //Guard statement to check for early errors in command decoder or implementation + if(address + 128 > 255) //Guard statement to check for early errors in command de.darkress.pic16f84sim.decoder or implementation { System.err.println("Guard statement triggered. The address must be 7Bit long and can therefore not exceed" + " 127"); diff --git a/de/darkress/pic16f84sim/registers/Stack.java b/de/darkress/pic16f84sim/registers/Stack.java new file mode 100644 index 0000000..8c99ccb --- /dev/null +++ b/de/darkress/pic16f84sim/registers/Stack.java @@ -0,0 +1,51 @@ +package de.darkress.pic16f84sim.registers; + + +public class Stack +{ + private static int[] stack = new int[8]; + private static int stackPointer = 0; + + public static void push(int data) + { + stack[stackPointer] = data; + pointNext(); + } + + public static int pop() + { + int tmp = stack[stackPointer]; + pointPrevious(); + return tmp; + } + + public static int peek() + { + return stack[(stackPointer + 7) % 8]; //Get TopOfStack -1 +8 = 7 and modulo 8 to avoid IndexOutOfBound + } + + private static void pointNext() + { + if(stackPointer == 7) + { + stackPointer = 0; + return; + } + stackPointer++; + } + + private static void pointPrevious() + { + if(stackPointer == 0) + { + stackPointer = 7; + return; + } + stackPointer--; + } + + public static int getStackPointer() + { + return stackPointer; + } +}