diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index f4f1480..35901c5 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -12,13 +12,14 @@ class Main public static void main(String[] args) { ArrayList program = new ArrayList<>(); - Memory.workingRegister = 0xAA; int input1 = 0x27FF; - program.add(CommandDecoder.decode(input1)); - - Memory.setPCLATH(0xFF); - program.get(0).execute(); - - //ProgramCounter.incPC(); + program.add(CommandDecoder.decode(0x3011)); + program.add(CommandDecoder.decode(0x2003)); + program.add(CommandDecoder.decode(0x3022)); + program.add(CommandDecoder.decode(0x0008)); + while(true) + { + program.get(ProgramCounter.getPc()).execute(); + } } } \ No newline at end of file diff --git a/de/darkress/pic16f84sim/commands/Return.java b/de/darkress/pic16f84sim/commands/Return.java new file mode 100644 index 0000000..e24e3f9 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Return.java @@ -0,0 +1,13 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; +import de.darkress.pic16f84sim.microcontroller.Stack; + +public class Return extends CommandUtils implements Command +{ + @Override + public void execute() + { + ProgramCounter.setPcFrom11BitLiteral(Stack.pop()); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 9253ef9..4c1942b 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -131,8 +131,7 @@ public class CommandDecoder if (input == 0x0008) { - //return(); - //This is the function name. Do not mistake this for a normal return! + return new Return(); } if (input == 0x0063) diff --git a/de/darkress/pic16f84sim/microcontroller/Stack.java b/de/darkress/pic16f84sim/microcontroller/Stack.java index 79d054c..c921e78 100644 --- a/de/darkress/pic16f84sim/microcontroller/Stack.java +++ b/de/darkress/pic16f84sim/microcontroller/Stack.java @@ -14,9 +14,8 @@ public class Stack public static int pop() { - int tmp = stack[stackPointer]; pointPrevious(); - return tmp; + return stack[stackPointer]; } public static int peek()