Functional Sublw instruction (#8)
* Functional Sublw instruction * Fixed zeroBit in Addlw after overflow and result == 0
This commit is contained in:
@@ -18,7 +18,7 @@ public class Addlw extends CommandUtils implements Command
|
|||||||
|
|
||||||
checkZeroBit(result);
|
checkZeroBit(result);
|
||||||
checkCarryBit(result);
|
checkCarryBit(result);
|
||||||
checkDigitCarryBit(result, literal);
|
checkDigitCarryBit(literal);
|
||||||
|
|
||||||
Memory.workingRegister = result % 256;
|
Memory.workingRegister = result % 256;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public class CommandUtils
|
|||||||
{
|
{
|
||||||
protected void checkZeroBit(int result)
|
protected void checkZeroBit(int result)
|
||||||
{
|
{
|
||||||
if(result == 0){
|
if((result % 256) == 0){
|
||||||
Memory.setZeroBit();
|
Memory.setZeroBit();
|
||||||
} else{
|
} else{
|
||||||
Memory.clearZeroBit();
|
Memory.clearZeroBit();
|
||||||
@@ -22,7 +22,7 @@ public class CommandUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkDigitCarryBit(int result, int literal)
|
protected void checkDigitCarryBit(int literal)
|
||||||
{
|
{
|
||||||
if(((Memory.workingRegister & 0x0F) + (literal & 0x0F)) > 15){
|
if(((Memory.workingRegister & 0x0F) + (literal & 0x0F)) > 15){
|
||||||
Memory.setDigitCarryBit();
|
Memory.setDigitCarryBit();
|
||||||
|
|||||||
45
commands/Sublw.java
Normal file
45
commands/Sublw.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package commands;
|
||||||
|
|
||||||
|
import 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,8 +95,7 @@ public class CommandDecoder
|
|||||||
return new Addlw(input);
|
return new Addlw(input);
|
||||||
//break;
|
//break;
|
||||||
case 0x3C00:
|
case 0x3C00:
|
||||||
//sublw();
|
return new Sublw(input);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(input & 0x3800)
|
switch(input & 0x3800)
|
||||||
|
|||||||
Reference in New Issue
Block a user