From d11f1b06f6a183bbe06a758f1772e62a11d304b0 Mon Sep 17 00:00:00 2001 From: darkress <30271678+darkressx@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:19:12 +0200 Subject: [PATCH] implemented bsf Instruction (#26) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/26 --- de/darkress/pic16f84sim/Main.java | 2 +- de/darkress/pic16f84sim/commands/Bsf.java | 26 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Bsf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index a9df39d..d322631 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -14,7 +14,7 @@ class Main ArrayList program = new ArrayList<>(); Memory.workingRegister = 0x01; Memory.setRegister(0x14, 0xA5); //240 << 224 - program.add(CommandDecoder.decode(0x1114)); + program.add(CommandDecoder.decode(0x1594)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Bsf.java b/de/darkress/pic16f84sim/commands/Bsf.java new file mode 100644 index 0000000..0555214 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Bsf.java @@ -0,0 +1,26 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Bsf extends BitOrientedCommandUtils implements Command +{ + private final int address; + private int bitPlacement; + + public Bsf(int input) + { + address = input & 0x007F; + bitPlacement = checkBitPlacement(input); + } + + @Override + public void execute() + { + int result = Memory.getRegister(address); + result |= (1 << bitPlacement); + + Memory.setRegister(address, result); + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index fa59768..c1f13c4 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -59,8 +59,7 @@ public class CommandDecoder case 0x1000: return new Bcf(input); case 0x1400: - //bsf(); - break; + return new Bsf(input); case 0x1800: //btfsc(); break;