implemented Stack (#10)
This commit is contained in:
25
de/darkress/pic16f84sim/commands/Addlw.java
Normal file
25
de/darkress/pic16f84sim/commands/Addlw.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class Addlw extends CommandUtils implements Command
|
||||
{
|
||||
private final int literal;
|
||||
|
||||
public Addlw(int input)
|
||||
{
|
||||
literal = input & 0x00FF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
int result = literal + Memory.workingRegister;
|
||||
|
||||
checkZeroBit(result);
|
||||
checkCarryBit(result);
|
||||
checkDigitCarryBit(literal);
|
||||
|
||||
Memory.workingRegister = result % 256;
|
||||
}
|
||||
}
|
||||
22
de/darkress/pic16f84sim/commands/Andlw.java
Normal file
22
de/darkress/pic16f84sim/commands/Andlw.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class Andlw extends CommandUtils implements Command
|
||||
{
|
||||
private final int literal;
|
||||
|
||||
public Andlw(int input)
|
||||
{
|
||||
literal = input & 0x00FF;
|
||||
}
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
int result = literal & Memory.workingRegister;
|
||||
|
||||
checkZeroBit(result);
|
||||
|
||||
Memory.workingRegister = result % 256;
|
||||
}
|
||||
}
|
||||
6
de/darkress/pic16f84sim/commands/Command.java
Normal file
6
de/darkress/pic16f84sim/commands/Command.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
public interface Command
|
||||
{
|
||||
void execute();
|
||||
}
|
||||
33
de/darkress/pic16f84sim/commands/CommandUtils.java
Normal file
33
de/darkress/pic16f84sim/commands/CommandUtils.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class CommandUtils
|
||||
{
|
||||
protected void checkZeroBit(int result)
|
||||
{
|
||||
if((result % 256) == 0){
|
||||
Memory.setZeroBit();
|
||||
} else{
|
||||
Memory.clearZeroBit();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkCarryBit(int result)
|
||||
{
|
||||
if(result > 255){
|
||||
Memory.setCarryBit();
|
||||
} else{
|
||||
Memory.clearCarryBit();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkDigitCarryBit(int literal)
|
||||
{
|
||||
if(((Memory.workingRegister & 0x0F) + (literal & 0x0F)) > 15){
|
||||
Memory.setDigitCarryBit();
|
||||
} else{
|
||||
Memory.clearDigitCarryBit();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
de/darkress/pic16f84sim/commands/Iorlw.java
Normal file
22
de/darkress/pic16f84sim/commands/Iorlw.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class Iorlw extends CommandUtils implements Command
|
||||
{
|
||||
private final int literal;
|
||||
|
||||
public Iorlw(int input)
|
||||
{
|
||||
literal = input & 0x00FF;
|
||||
}
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
int result = literal | Memory.workingRegister;
|
||||
|
||||
checkZeroBit(result);
|
||||
|
||||
Memory.workingRegister = result % 256;
|
||||
}
|
||||
}
|
||||
19
de/darkress/pic16f84sim/commands/Movlw.java
Normal file
19
de/darkress/pic16f84sim/commands/Movlw.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class Movlw extends CommandUtils implements Command
|
||||
{
|
||||
private final int literal;
|
||||
|
||||
public Movlw(int input)
|
||||
{
|
||||
literal = input & 0x00FF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
Memory.workingRegister = literal;
|
||||
}
|
||||
}
|
||||
45
de/darkress/pic16f84sim/commands/Sublw.java
Normal file
45
de/darkress/pic16f84sim/commands/Sublw.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package de.darkress.pic16f84sim.commands;
|
||||
|
||||
import de.darkress.pic16f84sim.registers.Memory;
|
||||
|
||||
public class Sublw extends CommandUtils implements Command
|
||||
{
|
||||
private final int literal;
|
||||
|
||||
public Sublw(int input)
|
||||
{
|
||||
literal = input & 0x00FF;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkCarryBit(int result)
|
||||
{
|
||||
if(result <= 255){
|
||||
Memory.clearCarryBit();
|
||||
} else{
|
||||
Memory.setCarryBit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDigitCarryBit(int literal)
|
||||
{
|
||||
if(((literal & 0x0F) - (Memory.workingRegister & 0x0F)) < 0){
|
||||
Memory.clearDigitCarryBit();
|
||||
} else{
|
||||
Memory.setDigitCarryBit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
int result = literal - Memory.workingRegister + 256;
|
||||
|
||||
checkZeroBit(result);
|
||||
checkCarryBit(result);
|
||||
checkDigitCarryBit(literal);
|
||||
|
||||
Memory.workingRegister = result % 256;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user