Addlw instruction (#4)
* Added addlw command * Write to program list * Included CommandUtils as helpter class. Sorted classes into packages * Revert changes on HelloWorld * Revert "Revert changes on HelloWorld" This reverts commit a08a336864fb2aa2bbc5a4e37ca360765774965e. * Added example execution of Addlw command
This commit is contained in:
25
commands/Addlw.java
Normal file
25
commands/Addlw.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package commands;
|
||||
|
||||
import 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(result, literal);
|
||||
|
||||
Memory.workingRegister = result % 256;
|
||||
}
|
||||
}
|
||||
6
commands/Command.java
Normal file
6
commands/Command.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package commands;
|
||||
|
||||
public interface Command
|
||||
{
|
||||
void execute();
|
||||
}
|
||||
33
commands/CommandUtils.java
Normal file
33
commands/CommandUtils.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package commands;
|
||||
|
||||
import registers.Memory;
|
||||
|
||||
public class CommandUtils
|
||||
{
|
||||
protected void checkZeroBit(int result)
|
||||
{
|
||||
if(result == 0){
|
||||
Memory.setZeroBit();
|
||||
} else{
|
||||
Memory.clearZeroBit();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkCarryBit(int result)
|
||||
{
|
||||
if(result > 255){
|
||||
Memory.setCarryBit();
|
||||
} else{
|
||||
Memory.clearCarryBit();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkDigitCarryBit(int result, int literal)
|
||||
{
|
||||
if(((Memory.workingRegister & 0x0F) + (literal & 0x0F)) > 15){
|
||||
Memory.setDigitCarryBit();
|
||||
} else{
|
||||
Memory.clearDigitCarryBit();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user