From 666cc2881b0255b9b1b7580e5bb040a4a6901a2a Mon Sep 17 00:00:00 2001 From: darkress Date: Tue, 30 May 2023 01:19:58 +0200 Subject: [PATCH] callInstruction (#3) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/3 --- de/darkress/pic16f84sim/Main.java | 3 +-- de/darkress/pic16f84sim/commands/Call.java | 21 +++++++++++++++++++ de/darkress/pic16f84sim/commands/Goto.java | 3 +-- .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- .../microcontroller/ProgramCounter.java | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Call.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 64bec6a..f4f1480 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -13,13 +13,12 @@ class Main ArrayList program = new ArrayList<>(); Memory.workingRegister = 0xAA; - int input1 = 0x2FFF; + int input1 = 0x27FF; program.add(CommandDecoder.decode(input1)); Memory.setPCLATH(0xFF); program.get(0).execute(); //ProgramCounter.incPC(); - } } \ No newline at end of file diff --git a/de/darkress/pic16f84sim/commands/Call.java b/de/darkress/pic16f84sim/commands/Call.java new file mode 100644 index 0000000..cd68115 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Call.java @@ -0,0 +1,21 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; +import de.darkress.pic16f84sim.microcontroller.Stack; + +public class Call extends CommandUtils implements Command +{ + private final int literal; + + public Call(int input) + { + literal = input & 0x07FF; + } + + @Override + public void execute() + { + Stack.push(ProgramCounter.getPc() + 1); + ProgramCounter.setPcFrom11BitLiteral(literal); + } +} diff --git a/de/darkress/pic16f84sim/commands/Goto.java b/de/darkress/pic16f84sim/commands/Goto.java index 7d3ffd8..23a1c1f 100644 --- a/de/darkress/pic16f84sim/commands/Goto.java +++ b/de/darkress/pic16f84sim/commands/Goto.java @@ -1,6 +1,5 @@ package de.darkress.pic16f84sim.commands; -import de.darkress.pic16f84sim.microcontroller.Memory; import de.darkress.pic16f84sim.microcontroller.ProgramCounter; public class Goto extends CommandUtils implements Command @@ -15,6 +14,6 @@ public class Goto extends CommandUtils implements Command @Override public void execute() { - ProgramCounter.setPcForGotoCall(literal); + ProgramCounter.setPcFrom11BitLiteral(literal); } } diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index c699140..9253ef9 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -100,8 +100,7 @@ public class CommandDecoder switch(input & 0x3800) { case 0x2000: - //call(); - break; + return new Call(input); case 0x2800: return new Goto(input); } diff --git a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java index 8b5888d..f9bccb9 100644 --- a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java +++ b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java @@ -11,7 +11,7 @@ public class ProgramCounter return pc; } - public static void setPcForGotoCall(int data) + public static void setPcFrom11BitLiteral(int data) { int pcl = data & 0x00FF; int pch = Memory.getPCLATH();