Compare commits
2 Commits
movwfInstr
...
decfszInst
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89f4845df6 | ||
|
|
e18ec6d167 |
@@ -12,9 +12,13 @@ class Main
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
ArrayList<Command> program = new ArrayList<>();
|
ArrayList<Command> program = new ArrayList<>();
|
||||||
Memory.workingRegister = 0x1A;
|
int input1 = 0x27FF;
|
||||||
Memory.setRegister(0x14, 0x1B);
|
program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W
|
||||||
program.add(CommandDecoder.decode(0x0094));
|
Memory.setRegister(0x14, 0x01);
|
||||||
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
|
program.add(CommandDecoder.decode(0x3F05));
|
||||||
for(int i = 0; i < program.size(); i++)
|
for(int i = 0; i < program.size(); i++)
|
||||||
{
|
{
|
||||||
program.get(ProgramCounter.getPc()).execute();
|
program.get(ProgramCounter.getPc()).execute();
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Clrf extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
private final int address;
|
|
||||||
private final boolean destinationBit;
|
|
||||||
|
|
||||||
public Clrf(int input)
|
|
||||||
{
|
|
||||||
address = input & 0x007F;
|
|
||||||
destinationBit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
final int result = 0;
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
writeToDestination(destinationBit, address, result);
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Clrw extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
final int result = 0;
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
Memory.workingRegister = result;
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Incf extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
private final int address;
|
|
||||||
private final boolean destinationBit;
|
|
||||||
|
|
||||||
public Incf(int input)
|
|
||||||
{
|
|
||||||
address = input & 0x007F;
|
|
||||||
destinationBit = checkDestinationBit(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
int result = Memory.getRegister(address) + 1; // Allow underflow
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
writeToDestination(destinationBit, address, result % 256); // Catch underflow
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Incfsz extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
private final int address;
|
|
||||||
private final boolean destinationBit;
|
|
||||||
|
|
||||||
public Incfsz(int input)
|
|
||||||
{
|
|
||||||
address = input & 0x007F;
|
|
||||||
destinationBit = checkDestinationBit(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
int result = Memory.getRegister(address) + 1;
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
writeToDestination(destinationBit, address, result % 256);
|
|
||||||
|
|
||||||
if((result % 256) == 0)
|
|
||||||
{
|
|
||||||
Nop nop = new Nop();
|
|
||||||
nop.execute();
|
|
||||||
}
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Iorwf extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
private final int address;
|
|
||||||
private final boolean destinationBit;
|
|
||||||
|
|
||||||
public Iorwf(int input)
|
|
||||||
{
|
|
||||||
address = input & 0x007F;
|
|
||||||
destinationBit = checkDestinationBit(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
int result = Memory.getRegister(address) | Memory.workingRegister;
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
writeToDestination(destinationBit, address, result);
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
|
|
||||||
public class Movf extends FileRegisterCommandUtils implements Command
|
|
||||||
{
|
|
||||||
private final int address;
|
|
||||||
private final boolean destinationBit;
|
|
||||||
|
|
||||||
public Movf(int input)
|
|
||||||
{
|
|
||||||
address = input & 0x007F;
|
|
||||||
destinationBit = checkDestinationBit(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
int result = Memory.getRegister(address);
|
|
||||||
|
|
||||||
checkZeroBit(result);
|
|
||||||
|
|
||||||
writeToDestination(destinationBit, address, result);
|
|
||||||
ProgramCounter.incPC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,13 +19,17 @@ public class CommandDecoder
|
|||||||
case 0xB00:
|
case 0xB00:
|
||||||
return new Decfsz(input);
|
return new Decfsz(input);
|
||||||
case 0xA00:
|
case 0xA00:
|
||||||
return new Incf(input);
|
//incf();
|
||||||
|
break;
|
||||||
case 0xF00:
|
case 0xF00:
|
||||||
return new Incfsz(input);
|
//incfsz();
|
||||||
|
break;
|
||||||
case 0x400:
|
case 0x400:
|
||||||
return new Iorwf(input);
|
//iorwf();
|
||||||
|
break;
|
||||||
case 0x800:
|
case 0x800:
|
||||||
return new Movf(input);
|
//movf();
|
||||||
|
break;
|
||||||
case 0xD00:
|
case 0xD00:
|
||||||
//rlf();
|
//rlf();
|
||||||
break;
|
break;
|
||||||
@@ -52,11 +56,14 @@ public class CommandDecoder
|
|||||||
switch(input & 0x3F80)
|
switch(input & 0x3F80)
|
||||||
{
|
{
|
||||||
case 0x180:
|
case 0x180:
|
||||||
return new Clrf(input);
|
//clrf();
|
||||||
|
break;
|
||||||
case 0x100:
|
case 0x100:
|
||||||
return new Clrw();
|
//clrw();
|
||||||
|
break;
|
||||||
case 0x80:
|
case 0x80:
|
||||||
return new Movwf(input);
|
//movwf();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(input & 0x3C00)
|
switch(input & 0x3C00)
|
||||||
|
|||||||
Reference in New Issue
Block a user