From b298b9765213bbc9b1e27bb400c79c78fba5f3b5 Mon Sep 17 00:00:00 2001 From: darkress <30271678+darkressx@users.noreply.github.com> Date: Wed, 7 Jun 2023 20:17:31 +0200 Subject: [PATCH] Added swapf Instruction (#23) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/23 --- de/darkress/pic16f84sim/Main.java | 4 +-- de/darkress/pic16f84sim/commands/Decfsz.java | 2 +- de/darkress/pic16f84sim/commands/Incfsz.java | 2 +- de/darkress/pic16f84sim/commands/Swapf.java | 27 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Swapf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index ad933ab..6f512c2 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -13,8 +13,8 @@ class Main ArrayList program = new ArrayList<>(); Memory.workingRegister = 0x01; - Memory.setRegister(0x14, 0x01); //240 << 224 - program.add(CommandDecoder.decode(0x0294)); + Memory.setRegister(0x14, 0xA5); //240 << 224 + program.add(CommandDecoder.decode(0x0E94)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Decfsz.java b/de/darkress/pic16f84sim/commands/Decfsz.java index 6ce38ca..948c5aa 100644 --- a/de/darkress/pic16f84sim/commands/Decfsz.java +++ b/de/darkress/pic16f84sim/commands/Decfsz.java @@ -26,7 +26,7 @@ public class Decfsz extends FileRegisterCommandUtils implements Command if((result % 256) == 0) { Nop nop = new Nop(); - nop.execute(); + nop.execute(); // TODO: What happens if an interrupt gets triggered during the nop execution? } ProgramCounter.incPC(); } diff --git a/de/darkress/pic16f84sim/commands/Incfsz.java b/de/darkress/pic16f84sim/commands/Incfsz.java index 3cbf1e5..e795c7c 100644 --- a/de/darkress/pic16f84sim/commands/Incfsz.java +++ b/de/darkress/pic16f84sim/commands/Incfsz.java @@ -26,7 +26,7 @@ public class Incfsz extends FileRegisterCommandUtils implements Command if((result % 256) == 0) { Nop nop = new Nop(); - nop.execute(); + nop.execute(); // TODO: What happens if an interrupt gets triggered during the nop execution? } ProgramCounter.incPC(); } diff --git a/de/darkress/pic16f84sim/commands/Swapf.java b/de/darkress/pic16f84sim/commands/Swapf.java new file mode 100644 index 0000000..8bfed2a --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Swapf.java @@ -0,0 +1,27 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Swapf extends FileRegisterCommandUtils implements Command +{ + private final int address; + private final boolean destinationBit; + + public Swapf(int input) + { + address = input & 0x007F; + destinationBit = checkDestinationBit(input); + } + + @Override + public void execute() + { + int result = (Memory.getRegister(address) <<4) & 0xF0; + int tmp = Memory.getRegister(address) >>4; + result += tmp; + + writeToDestination(destinationBit, address, result); + ProgramCounter.incPC(); + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 9e88a03..5b4ef6c 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -33,8 +33,7 @@ public class CommandDecoder case 0x200: return new Subwf(input); case 0xE00: - //swapf(); - break; + return new Swapf(input); case 0x600: //xorwf(); break;