Compare commits

..

2 Commits

Author SHA1 Message Date
Darkress
2f8adb70c4 implemented Rlf Instruction 2023-06-06 01:09:16 +02:00
darkress
40b7a4a478 implemented Movwf instruction (#19)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#19
2023-06-06 00:00:58 +02:00
4 changed files with 46 additions and 7 deletions

View File

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

View File

@@ -0,0 +1,36 @@
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 carry = Memory.getCarryBit();
int tmp = carry;
carry = register >>7;
register = ((register <<1) + tmp) & 0xFF;
if(carry == 1)
{
Memory.setCarryBit();
} else if(carry == 0){
Memory.clearCarryBit();
}
writeToDestination(destinationBit, address, register);
ProgramCounter.incPC();
}
}

View File

@@ -27,8 +27,7 @@ public class CommandDecoder
case 0x800:
return new Movf(input);
case 0xD00:
//rlf();
break;
return new Rlf(input);
case 0xC00:
//rrf();
break;

View File

@@ -153,9 +153,13 @@ public class Memory
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()