'Simplified' decoder by using switches
This commit is contained in:
@@ -1,114 +1,144 @@
|
||||
public class CommandDecoder
|
||||
{
|
||||
public void CommandDecoder(String input)
|
||||
public CommandDecoder(int input)
|
||||
{
|
||||
int binaryInput = Integer.parseInt(input);
|
||||
switch(input & 0x3F00)
|
||||
{
|
||||
case 0x700:
|
||||
//addwf();
|
||||
break;
|
||||
case 0x500:
|
||||
//andwf();
|
||||
break;
|
||||
case 0x900:
|
||||
//comf();
|
||||
break;
|
||||
case 0x300:
|
||||
//decf();
|
||||
break;
|
||||
case 0xB00:
|
||||
//decfsz();
|
||||
break;
|
||||
case 0xA00:
|
||||
//incf();
|
||||
break;
|
||||
case 0xF00:
|
||||
//incfsz();
|
||||
break;
|
||||
case 0x400:
|
||||
//iorwf();
|
||||
break;
|
||||
case 0x800:
|
||||
//movf();
|
||||
break;
|
||||
case 0xD00:
|
||||
//rlf();
|
||||
break;
|
||||
case 0xC00:
|
||||
//rrf();
|
||||
break;
|
||||
case 0x200:
|
||||
//subwf();
|
||||
break;
|
||||
case 0xE00:
|
||||
//swapf();
|
||||
break;
|
||||
case 0x600:
|
||||
//xorwf();
|
||||
break;
|
||||
case 0x3900:
|
||||
//andlw();
|
||||
break;
|
||||
case 0x3800:
|
||||
//iorlw();
|
||||
break;
|
||||
case 0x3A00:
|
||||
//xorlw();
|
||||
break;
|
||||
}
|
||||
|
||||
if ((binaryInput & 0x3F00) == 0x700)
|
||||
switch(input & 0x3F80)
|
||||
{
|
||||
//ADDWF();
|
||||
} else if ((binaryInput & 0x3F00) == 0x500)
|
||||
case 0x180:
|
||||
//clrf();
|
||||
break;
|
||||
case 0x100:
|
||||
//clrw();
|
||||
break;
|
||||
case 0x80:
|
||||
//movwf();
|
||||
break;
|
||||
}
|
||||
|
||||
switch(input & 0x3C00)
|
||||
{
|
||||
//ANDWF();
|
||||
} else if ((binaryInput & 0x3F80) == 0x180)
|
||||
case 0x1000:
|
||||
//bcf();
|
||||
break;
|
||||
case 0x1400:
|
||||
//bsf();
|
||||
break;
|
||||
case 0x1800:
|
||||
//btfsc();
|
||||
break;
|
||||
case 0x1C00:
|
||||
//btfss();
|
||||
break;
|
||||
}
|
||||
|
||||
switch(input & 0x3E00)
|
||||
{
|
||||
//CLRF();
|
||||
} else if ((binaryInput & 0x3F80) == 0x100)
|
||||
case 0x3E00:
|
||||
//addlw();
|
||||
break;
|
||||
case 0x3C00:
|
||||
//sublw();
|
||||
break;
|
||||
}
|
||||
|
||||
switch(input & 0x3800)
|
||||
{
|
||||
//CLRW();
|
||||
} else if ((binaryInput & 0x3F00) == 0x900)
|
||||
case 0x2000:
|
||||
//call();
|
||||
break;
|
||||
case 0x2800:
|
||||
//goto();
|
||||
break;
|
||||
}
|
||||
|
||||
switch(input & 0x3C00)
|
||||
{
|
||||
//COMF();
|
||||
} else if ((binaryInput & 0x3F00) == 0x300)
|
||||
{
|
||||
//DECF();
|
||||
} else if ((binaryInput & 0x3F00) == 0xB00)
|
||||
{
|
||||
//DECFSZ();
|
||||
} else if ((binaryInput & 0x3F00) == 0xA00)
|
||||
{
|
||||
//INCF();
|
||||
} else if ((binaryInput & 0x3F00) == 0xF00)
|
||||
{
|
||||
//INCFSZ();
|
||||
} else if ((binaryInput & 0x3F00) == 0x400)
|
||||
{
|
||||
//IORWF();
|
||||
} else if ((binaryInput & 0x3F00) == 0x800)
|
||||
{
|
||||
//MOVF();
|
||||
} else if ((binaryInput & 0x3F80) == 0x80)
|
||||
{
|
||||
//MOVWF();
|
||||
} else if ((binaryInput & 0x7FF) == 0x0)
|
||||
case 0x3000:
|
||||
//movlw();
|
||||
break;
|
||||
case 0x3400:
|
||||
//retlw();
|
||||
break;
|
||||
}
|
||||
|
||||
if ((input | 0x0060) == 0x0060)
|
||||
{
|
||||
//NOP();
|
||||
} else if ((binaryInput & 0x3F00) == 0xD00)
|
||||
{
|
||||
//RLF();
|
||||
} else if ((binaryInput & 0x3F00) == 0xC00)
|
||||
{
|
||||
//RRF();
|
||||
} else if ((binaryInput & 0x3F00) == 0x200)
|
||||
{
|
||||
//SUBWF();
|
||||
} else if ((binaryInput & 0x3F00) == 0xE00)
|
||||
{
|
||||
//SWAPF();
|
||||
} else if ((binaryInput & 0x3F00) == 0x600)
|
||||
{
|
||||
//XORWF();
|
||||
} else if ((binaryInput & 0xF000) == 0x4000)
|
||||
{
|
||||
//BCF
|
||||
} else if ((binaryInput & 0xF000) == 0x5000)
|
||||
{
|
||||
//BSF
|
||||
} else if ((binaryInput & 0xF000) == 0x6000)
|
||||
{
|
||||
//BTFSC
|
||||
} else if ((binaryInput & 0xF000) == 0x7000)
|
||||
{
|
||||
//BTFSS
|
||||
} else if ((binaryInput & 0x3E00) == 0x3E00)
|
||||
{
|
||||
//ADDLW
|
||||
} else if ((binaryInput & 0x3F00) == 0x3900)
|
||||
{
|
||||
//ANDLW
|
||||
} else if ((binaryInput & 0x3800) == 0x2000)
|
||||
{
|
||||
//CALL
|
||||
} else if (binaryInput == 0x0064)
|
||||
}
|
||||
|
||||
if (input == 0x0064)
|
||||
{
|
||||
//Clear Watchdog Timer
|
||||
} else if ((binaryInput & 0x3800) == 0x2800)
|
||||
{
|
||||
//GOTO
|
||||
} else if ((binaryInput & 0x3F00) == 0x3800)
|
||||
{
|
||||
//IORLW
|
||||
} else if ((binaryInput & 0x3C00) == 0x3000)
|
||||
{
|
||||
//MOVLW
|
||||
} else if (binaryInput == 0x0009)
|
||||
}
|
||||
|
||||
if (input == 0x0009)
|
||||
{
|
||||
//RETFIE
|
||||
} else if ((binaryInput & 0x3C00) == 0x3400)
|
||||
{
|
||||
//RETLW
|
||||
} else if (binaryInput == 0x0008)
|
||||
}
|
||||
|
||||
if (input == 0x0008)
|
||||
{
|
||||
//RETURN
|
||||
} else if (binaryInput == 0x0063)
|
||||
}
|
||||
|
||||
if (input == 0x0063)
|
||||
{
|
||||
//SLEEP
|
||||
} else if ((binaryInput & 0x3E00) == 0x3C00)
|
||||
{
|
||||
//SUBLW
|
||||
} else if ((binaryInput & 0x3F00) == 0x3A00)
|
||||
{
|
||||
//XORLW
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
String input = "9";
|
||||
CommandDecoder commandDecoder = new CommandDecoder();
|
||||
commandDecoder.CommandDecoder(input);
|
||||
int binaryInput = Integer.parseInt(input);
|
||||
System.out.println(binaryInput);
|
||||
int input = Integer.decode("0x0070");
|
||||
CommandDecoder commandDecoder = new CommandDecoder(input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user