Compare commits

..

1 Commits

Author SHA1 Message Date
Darkress
30deff96a8 implemented Movwf instruction 2023-06-05 23:58:15 +02:00
5 changed files with 9 additions and 81 deletions

View File

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

View File

@@ -1,35 +0,0 @@
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

@@ -1,35 +0,0 @@
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,9 +27,11 @@ public class CommandDecoder
case 0x800:
return new Movf(input);
case 0xD00:
return new Rlf(input);
//rlf();
break;
case 0xC00:
return new Rrf(input);
//rrf();
break;
case 0x200:
//subwf();
break;

View File

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