implemented Rrf Instruction (#21)

Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#21
This commit was merged in pull request #21.
This commit is contained in:
darkress
2023-06-06 02:42:28 +02:00
parent 01bd5acb46
commit d25a66134a
4 changed files with 43 additions and 10 deletions

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