Compare commits

...

2 Commits

Author SHA1 Message Date
Darkress
c6b5e3989e implemented btfsc Instruction 2023-06-07 21:30:49 +02:00
darkress
d11f1b06f6 implemented bsf Instruction (#26)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#26
2023-06-07 21:19:12 +02:00
4 changed files with 58 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ class Main
ArrayList<Command> program = new ArrayList<>();
Memory.workingRegister = 0x01;
Memory.setRegister(0x14, 0xA5); //240 << 224
program.add(CommandDecoder.decode(0x1114));
program.add(CommandDecoder.decode(0x1894));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();

View File

@@ -0,0 +1,26 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Bsf extends BitOrientedCommandUtils implements Command
{
private final int address;
private int bitPlacement;
public Bsf(int input)
{
address = input & 0x007F;
bitPlacement = checkBitPlacement(input);
}
@Override
public void execute()
{
int result = Memory.getRegister(address);
result |= (1 << bitPlacement);
Memory.setRegister(address, result);
ProgramCounter.incPC();
}
}

View File

@@ -0,0 +1,29 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Btfsc extends BitOrientedCommandUtils implements Command
{
private final int address;
private int bitPlacement;
public Btfsc(int input)
{
address = input & 0x007F;
bitPlacement = checkBitPlacement(input);
}
@Override
public void execute()
{
int result = Memory.getRegister(address);
if((result & (1 << bitPlacement)) == 0) //Test if bit is clear
{
ProgramCounter.incPC();
}
ProgramCounter.incPC();
}
}

View File

@@ -59,11 +59,9 @@ public class CommandDecoder
case 0x1000:
return new Bcf(input);
case 0x1400:
//bsf();
break;
return new Bsf(input);
case 0x1800:
//btfsc();
break;
return new Btfsc(input);
case 0x1C00:
//btfss();
break;