From 9a21d9256fb9b0cc563a6e0d66fd6457535e9ba5 Mon Sep 17 00:00:00 2001 From: darkress Date: Fri, 2 Jun 2023 23:50:34 +0200 Subject: [PATCH] implemented Clrf Instruction --- de/darkress/pic16f84sim/Main.java | 4 +-- de/darkress/pic16f84sim/commands/Clrf.java | 27 +++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Clrf.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 75b3207..dc0c85b 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -12,8 +12,8 @@ class Main public static void main(String[] args) { ArrayList program = new ArrayList<>(); - Memory.workingRegister = 0x10; - program.add(CommandDecoder.decode(0x123)); //Write 0x11 to W + Memory.setRegister(0x14, 0xFF); + program.add(CommandDecoder.decode(0x0194)); for(int i = 0; i < program.size(); i++) { program.get(ProgramCounter.getPc()).execute(); diff --git a/de/darkress/pic16f84sim/commands/Clrf.java b/de/darkress/pic16f84sim/commands/Clrf.java new file mode 100644 index 0000000..6a809f6 --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Clrf.java @@ -0,0 +1,27 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; +import de.darkress.pic16f84sim.microcontroller.ProgramCounter; + +public class Clrf extends FileRegisterCommandUtils implements Command +{ + private final int address; + private final boolean destinationBit; + + public Clrf(int input) + { + address = input & 0x007F; + destinationBit = true; + } + + @Override + public void execute() + { + final int result = 0; + + 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 fee3db5..f480a7d 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -54,8 +54,7 @@ public class CommandDecoder switch(input & 0x3F80) { case 0x180: - //clrf(); - break; + return new Clrf(input); case 0x100: return new Clrw(); case 0x80: