From 4c7dbdb5485999d79ca2c4334b016d523acd94d1 Mon Sep 17 00:00:00 2001 From: Darkress <30271678+DarkressX@users.noreply.github.com> Date: Tue, 6 Jun 2023 02:42:11 +0200 Subject: [PATCH] implemented Rrf Instruction --- de/darkress/pic16f84sim/Main.java | 4 +-- de/darkress/pic16f84sim/commands/Rlf.java | 11 +++--- de/darkress/pic16f84sim/commands/Rrf.java | 35 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +- 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Rrf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 46cf67d..607b558 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -13,8 +13,8 @@ class Main ArrayList program = new ArrayList<>(); Memory.clearCarryBit(); - Memory.setRegister(0x14, 0B11110000); //240 << 224 - program.add(CommandDecoder.decode(0x0D94)); + Memory.setRegister(0x14, 0B00000001); //240 << 224 + program.add(CommandDecoder.decode(0x0C94)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Rlf.java b/de/darkress/pic16f84sim/commands/Rlf.java index 83a80bc..ce73fe7 100644 --- a/de/darkress/pic16f84sim/commands/Rlf.java +++ b/de/darkress/pic16f84sim/commands/Rlf.java @@ -18,15 +18,14 @@ public class Rlf extends FileRegisterCommandUtils implements Command public void execute() { int register = Memory.getRegister(address); - int carry = Memory.getCarryBit(); - int tmp = carry; - carry = register >>7; - register = ((register <<1) + tmp) & 0xFF; + int newCarry = register >>7; + int oldCarry = Memory.getCarryBit(); + register = ((register <<1) + oldCarry) & 0xFF; - if(carry == 1) + if(newCarry == 1) { Memory.setCarryBit(); - } else if(carry == 0){ + } else if(newCarry == 0){ Memory.clearCarryBit(); } diff --git a/de/darkress/pic16f84sim/commands/Rrf.java b/de/darkress/pic16f84sim/commands/Rrf.java new file mode 100644 index 0000000..7257279 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Rrf.java @@ -0,0 +1,35 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Rrf extends FileRegisterCommandUtils implements Command +{ + private final int address; + private final boolean destinationBit; + + public Rrf(int input) + { + address = input & 0x007F; + destinationBit = checkDestinationBit(input); + } + + @Override + public void execute() + { + int register = Memory.getRegister(address); + int newCarry = register & 0x01; + int oldCarry = Memory.getCarryBit(); + register = (oldCarry << 7) + (register >>1); + + if(newCarry == 1) + { + Memory.setCarryBit(); + } else if(newCarry == 0){ + Memory.clearCarryBit(); + } + + writeToDestination(destinationBit, address, register); + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index b233a97..6657fb0 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -29,8 +29,7 @@ public class CommandDecoder case 0xD00: return new Rlf(input); case 0xC00: - //rrf(); - break; + return new Rrf(input); case 0x200: //subwf(); break; -- 2.49.1