From bfbec8d525963b6985acdda36ba35f304fe91bb4 Mon Sep 17 00:00:00 2001 From: darkress Date: Mon, 29 May 2023 15:39:04 +0200 Subject: [PATCH] XorlwInstruction (#1) Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com> Reviewed-on: https://git.darkress.xyz/darkress/pic16f84-sim/pulls/1 --- de/darkress/pic16f84sim/Main.java | 23 +++++-------------- de/darkress/pic16f84sim/commands/Xorlw.java | 22 ++++++++++++++++++ .../pic16f84sim/decoder/CommandDecoder.java | 3 +-- .../microcontroller/ProgramCounter.java | 5 ++++ 4 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 de/darkress/pic16f84sim/commands/Xorlw.java diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 03cb934..4b64698 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -1,29 +1,18 @@ package de.darkress.pic16f84sim; -import de.darkress.pic16f84sim.microcontroller.Stack; +import de.darkress.pic16f84sim.commands.Command; +import de.darkress.pic16f84sim.decoder.CommandDecoder; +import de.darkress.pic16f84sim.microcontroller.Memory; +import java.util.ArrayList; class Main { public static void main(String[] args) { - /* ArrayList program = new ArrayList<>(); - int input1 = 0x3EFF; + Memory.workingRegister = 0xAA; + int input1 = 0x3AFF; program.add(CommandDecoder.decode(input1)); program.get(0).execute(); - */ - - - for(int i = 0; i < 8; i++) - { - Stack.push(i); - } - - for(int i = 0; i < 16; i++) - { - System.out.println(Stack.peek()); - Stack.pop(); - } - } } \ No newline at end of file diff --git a/de/darkress/pic16f84sim/commands/Xorlw.java b/de/darkress/pic16f84sim/commands/Xorlw.java new file mode 100644 index 0000000..a3e21af --- /dev/null +++ b/de/darkress/pic16f84sim/commands/Xorlw.java @@ -0,0 +1,22 @@ +package de.darkress.pic16f84sim.commands; + +import de.darkress.pic16f84sim.microcontroller.Memory; + +public class Xorlw extends CommandUtils implements Command +{ + private final int literal; + + public Xorlw(int input) + { + literal = input & 0x00FF; + } + @Override + public void execute() + { + int result = literal ^ Memory.workingRegister; + + checkZeroBit(result); + + Memory.workingRegister = result % 256; + } +} diff --git a/de/darkress/pic16f84sim/decoder/CommandDecoder.java b/de/darkress/pic16f84sim/decoder/CommandDecoder.java index 9c6d79a..00f0f9e 100644 --- a/de/darkress/pic16f84sim/decoder/CommandDecoder.java +++ b/de/darkress/pic16f84sim/decoder/CommandDecoder.java @@ -55,8 +55,7 @@ public class CommandDecoder case 0x3800: return new Iorlw(input); case 0x3A00: - //xorlw(); - break; + return new Xorlw(input); } switch(input & 0x3F80) diff --git a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java index 7085d95..196d02e 100644 --- a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java +++ b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java @@ -15,4 +15,9 @@ public class ProgramCounter { ProgramCounter.PC = PC; } + + public static void incPC() + { + PC++; + } }