Compare commits

..

3 Commits

Author SHA1 Message Date
Darkress
21ee79f6ef Added Xorwf Instruction 2023-06-07 20:20:35 +02:00
darkress
b298b97652 Added swapf Instruction (#23)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#23
2023-06-07 20:17:31 +02:00
darkress
d8ed3ab9b1 implemented subwf Instruction (#22)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#22
2023-06-06 07:35:12 +02:00
6 changed files with 60 additions and 8 deletions

View File

@@ -13,8 +13,8 @@ class Main
ArrayList<Command> 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(0x0694));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,27 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Xorwf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Xorwf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int result = Memory.getRegister(address) ^ Memory.workingRegister;
checkZeroBit(result);
writeToDestination(destinationBit, address, result);
ProgramCounter.incPC();
}
}

View File

@@ -33,11 +33,9 @@ public class CommandDecoder
case 0x200:
return new Subwf(input);
case 0xE00:
//swapf();
break;
return new Swapf(input);
case 0x600:
//xorwf();
break;
return new Xorwf(input);
case 0x3900:
return new Andlw(input);
case 0x3800: