From ccc7f72c61ca4aeabf9c090c4c13839d29b18a46 Mon Sep 17 00:00:00 2001 From: Darkress <30271678+DarkressX@users.noreply.github.com> Date: Wed, 31 May 2023 19:42:49 +0200 Subject: [PATCH] implemented Andwf instruction --- de/darkress/pic16f84sim/Main.java | 2 +- de/darkress/pic16f84sim/commands/Andwf.java | 27 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Andwf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 0c8f367..dbe245e 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -15,7 +15,7 @@ class Main int input1 = 0x27FF; program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W Memory.setRegister(0x14, 0x14); - program.add(CommandDecoder.decode(0x0714)); + program.add(CommandDecoder.decode(0x0594)); for(int i = 0; i < 2; i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Andwf.java b/de/darkress/pic16f84sim/commands/Andwf.java new file mode 100644 index 0000000..9d51d1a --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Andwf.java @@ -0,0 +1,27 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Andwf extends FileRegisterCommandUtils implements Command +{ + private final int address; + private final boolean destinationBit; + + public Andwf(int input) + { + address = input & 0x007F; + destinationBit = checkDestinationBit(input); + } + + @Override + public void execute() + { + int result = Memory.getRegister(address) & Memory.workingRegister; + + checkZeroBit(result); + + writeToDestination(destinationBit, address, result); + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 3e692f6..9a2318c 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -11,8 +11,7 @@ public class CommandDecoder case 0x700: return new Addwf(input); case 0x500: - //andwf(); - break; + return new Andwf(input); case 0x900: //comf(); break;