implemented Rrf Instruction #21

Merged
Darkress merged 1 commits from RrfInstruction into main 2023-06-06 02:42:28 +02:00
4 changed files with 43 additions and 10 deletions

View File

@@ -13,8 +13,8 @@ class Main
ArrayList<Command> program = new ArrayList<>();
Memory.clearCarryBit();
Memory.setRegister(0x14, 0B11110000); //240 << 224
program.add(CommandDecoder.decode(0x0D94));
Memory.setRegister(0x14, 0B00000001); //240 << 224
program.add(CommandDecoder.decode(0x0C94));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();

View File

@@ -18,15 +18,14 @@ public class Rlf extends FileRegisterCommandUtils implements Command
public void execute()
{
int register = Memory.getRegister(address);
int carry = Memory.getCarryBit();
int tmp = carry;
carry = register >>7;
register = ((register <<1) + tmp) & 0xFF;
int newCarry = register >>7;
int oldCarry = Memory.getCarryBit();
register = ((register <<1) + oldCarry) & 0xFF;
if(carry == 1)
if(newCarry == 1)
{
Memory.setCarryBit();
} else if(carry == 0){
} else if(newCarry == 0){
Memory.clearCarryBit();
}

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

@@ -29,8 +29,7 @@ public class CommandDecoder
case 0xD00:
return new Rlf(input);
case 0xC00:
//rrf();
break;
return new Rrf(input);
case 0x200:
//subwf();
break;