From 7eab465ffffe5ef058b56e00f9496ed127dfbfe9 Mon Sep 17 00:00:00 2001 From: darkress <30271678+darkressx@users.noreply.github.com> Date: Wed, 31 May 2023 22:13:12 +0200 Subject: [PATCH] implement Incf Instruction (#13) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/13 --- de/darkress/pic16f84sim/Main.java | 5 +--- de/darkress/pic16f84sim/commands/Incf.java | 27 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Incf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 02b4be9..3da805b 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -15,10 +15,7 @@ class Main int input1 = 0x27FF; program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W Memory.setRegister(0x14, 0x01); - program.add(CommandDecoder.decode(0x0B94)); - program.add(CommandDecoder.decode(0x0B94)); - program.add(CommandDecoder.decode(0x0B94)); - program.add(CommandDecoder.decode(0x3F05)); + program.add(CommandDecoder.decode(0x0A94)); //Write 0x11 to W for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Incf.java b/de/darkress/pic16f84sim/commands/Incf.java new file mode 100644 index 0000000..6875361 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Incf.java @@ -0,0 +1,27 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Incf extends FileRegisterCommandUtils implements Command +{ + private final int address; + private final boolean destinationBit; + + public Incf(int input) + { + address = input & 0x007F; + destinationBit = checkDestinationBit(input); + } + + @Override + public void execute() + { + int result = Memory.getRegister(address) + 1; // Allow underflow + + checkZeroBit(result); + + writeToDestination(destinationBit, address, result % 256); // Catch underflow + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 2bf41cc..1030e96 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -19,8 +19,7 @@ public class CommandDecoder case 0xB00: return new Decfsz(input); case 0xA00: - //incf(); - break; + return new Incf(input); case 0xF00: //incfsz(); break;