Compare commits

...

2 Commits

Author SHA1 Message Date
Darkress
4c7dbdb548 implemented Rrf Instruction 2023-06-06 02:42:11 +02:00
darkress
01bd5acb46 implemented Rlf Instruction (#20)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#20
2023-06-06 02:22:29 +02:00
5 changed files with 81 additions and 9 deletions

View File

@@ -12,9 +12,9 @@ class Main
public static void main(String[] args) { public static void main(String[] args) {
ArrayList<Command> program = new ArrayList<>(); ArrayList<Command> program = new ArrayList<>();
Memory.workingRegister = 0x1A; Memory.clearCarryBit();
Memory.setRegister(0x14, 0x1B); Memory.setRegister(0x14, 0B00000001); //240 << 224
program.add(CommandDecoder.decode(0x0094)); program.add(CommandDecoder.decode(0x0C94));
for(int i = 0; i < program.size(); i++) for(int i = 0; i < program.size(); i++)
{ {
program.get(ProgramCounter.getPc()).execute(); program.get(ProgramCounter.getPc()).execute();

View File

@@ -0,0 +1,35 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Rlf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Rlf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int register = Memory.getRegister(address);
int newCarry = register >>7;
int oldCarry = Memory.getCarryBit();
register = ((register <<1) + oldCarry) & 0xFF;
if(newCarry == 1)
{
Memory.setCarryBit();
} else if(newCarry == 0){
Memory.clearCarryBit();
}
writeToDestination(destinationBit, address, register);
ProgramCounter.incPC();
}
}

View File

@@ -0,0 +1,35 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Rrf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Rrf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int register = Memory.getRegister(address);
int newCarry = register & 0x01;
int oldCarry = Memory.getCarryBit();
register = (oldCarry << 7) + (register >>1);
if(newCarry == 1)
{
Memory.setCarryBit();
} else if(newCarry == 0){
Memory.clearCarryBit();
}
writeToDestination(destinationBit, address, register);
ProgramCounter.incPC();
}
}

View File

@@ -27,11 +27,9 @@ public class CommandDecoder
case 0x800: case 0x800:
return new Movf(input); return new Movf(input);
case 0xD00: case 0xD00:
//rlf(); return new Rlf(input);
break;
case 0xC00: case 0xC00:
//rrf(); return new Rrf(input);
break;
case 0x200: case 0x200:
//subwf(); //subwf();
break; break;

View File

@@ -153,9 +153,13 @@ public class Memory
memory[0x03] &= 0xFD; memory[0x03] &= 0xFD;
} }
public static boolean getCarryBit() public static int getCarryBit()
{ {
return (memory[0x03] & 0x01) == 0x01; if((memory[0x03] & 0x01) == 0x01)
{
return 1;
}
else return 0;
} }
public static void setCarryBit() public static void setCarryBit()