Compare commits

..

1 Commits

Author SHA1 Message Date
Darkress
36f018835f implemented Movf Instruction 2023-06-04 20:41:56 +02:00
5 changed files with 9 additions and 72 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, 0B11110000); //240 << 224
program.add(CommandDecoder.decode(0x0D94));
Memory.workingRegister = 0x1A;
Memory.setRegister(0x14, 0x1B);
program.add(CommandDecoder.decode(0x0894));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();

View File

@@ -1,25 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Movwf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Movwf(int input)
{
address = input & 0x007F;
destinationBit = true;
}
@Override
public void execute()
{
int result = Memory.workingRegister;
writeToDestination(destinationBit, address, result);
ProgramCounter.incPC();
}
}

View File

@@ -1,36 +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 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,7 +27,8 @@ public class CommandDecoder
case 0x800:
return new Movf(input);
case 0xD00:
return new Rlf(input);
//rlf();
break;
case 0xC00:
//rrf();
break;
@@ -55,7 +56,8 @@ public class CommandDecoder
case 0x100:
return new Clrw();
case 0x80:
return new Movwf(input);
//movwf();
break;
}
switch(input & 0x3C00)

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