'Simplified' decoder by using switches
This commit is contained in:
@@ -1,114 +1,144 @@
|
|||||||
public class CommandDecoder
|
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();
|
case 0x180:
|
||||||
} else if ((binaryInput & 0x3F00) == 0x500)
|
//clrf();
|
||||||
|
break;
|
||||||
|
case 0x100:
|
||||||
|
//clrw();
|
||||||
|
break;
|
||||||
|
case 0x80:
|
||||||
|
//movwf();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(input & 0x3C00)
|
||||||
{
|
{
|
||||||
//ANDWF();
|
case 0x1000:
|
||||||
} else if ((binaryInput & 0x3F80) == 0x180)
|
//bcf();
|
||||||
|
break;
|
||||||
|
case 0x1400:
|
||||||
|
//bsf();
|
||||||
|
break;
|
||||||
|
case 0x1800:
|
||||||
|
//btfsc();
|
||||||
|
break;
|
||||||
|
case 0x1C00:
|
||||||
|
//btfss();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(input & 0x3E00)
|
||||||
{
|
{
|
||||||
//CLRF();
|
case 0x3E00:
|
||||||
} else if ((binaryInput & 0x3F80) == 0x100)
|
//addlw();
|
||||||
|
break;
|
||||||
|
case 0x3C00:
|
||||||
|
//sublw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(input & 0x3800)
|
||||||
{
|
{
|
||||||
//CLRW();
|
case 0x2000:
|
||||||
} else if ((binaryInput & 0x3F00) == 0x900)
|
//call();
|
||||||
|
break;
|
||||||
|
case 0x2800:
|
||||||
|
//goto();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(input & 0x3C00)
|
||||||
{
|
{
|
||||||
//COMF();
|
case 0x3000:
|
||||||
} else if ((binaryInput & 0x3F00) == 0x300)
|
//movlw();
|
||||||
{
|
break;
|
||||||
//DECF();
|
case 0x3400:
|
||||||
} else if ((binaryInput & 0x3F00) == 0xB00)
|
//retlw();
|
||||||
{
|
break;
|
||||||
//DECFSZ();
|
}
|
||||||
} else if ((binaryInput & 0x3F00) == 0xA00)
|
|
||||||
{
|
if ((input | 0x0060) == 0x0060)
|
||||||
//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)
|
|
||||||
{
|
{
|
||||||
//NOP();
|
//NOP();
|
||||||
} else if ((binaryInput & 0x3F00) == 0xD00)
|
}
|
||||||
{
|
|
||||||
//RLF();
|
if (input == 0x0064)
|
||||||
} 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)
|
|
||||||
{
|
{
|
||||||
//Clear Watchdog Timer
|
//Clear Watchdog Timer
|
||||||
} else if ((binaryInput & 0x3800) == 0x2800)
|
}
|
||||||
{
|
|
||||||
//GOTO
|
if (input == 0x0009)
|
||||||
} else if ((binaryInput & 0x3F00) == 0x3800)
|
|
||||||
{
|
|
||||||
//IORLW
|
|
||||||
} else if ((binaryInput & 0x3C00) == 0x3000)
|
|
||||||
{
|
|
||||||
//MOVLW
|
|
||||||
} else if (binaryInput == 0x0009)
|
|
||||||
{
|
{
|
||||||
//RETFIE
|
//RETFIE
|
||||||
} else if ((binaryInput & 0x3C00) == 0x3400)
|
}
|
||||||
{
|
|
||||||
//RETLW
|
if (input == 0x0008)
|
||||||
} else if (binaryInput == 0x0008)
|
|
||||||
{
|
{
|
||||||
//RETURN
|
//RETURN
|
||||||
} else if (binaryInput == 0x0063)
|
}
|
||||||
|
|
||||||
|
if (input == 0x0063)
|
||||||
{
|
{
|
||||||
//SLEEP
|
//SLEEP
|
||||||
} else if ((binaryInput & 0x3E00) == 0x3C00)
|
|
||||||
{
|
|
||||||
//SUBLW
|
|
||||||
} else if ((binaryInput & 0x3F00) == 0x3A00)
|
|
||||||
{
|
|
||||||
//XORLW
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,7 @@
|
|||||||
class HelloWorld {
|
class HelloWorld {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello, World!");
|
System.out.println("Hello, World!");
|
||||||
String input = "9";
|
int input = Integer.decode("0x0070");
|
||||||
CommandDecoder commandDecoder = new CommandDecoder();
|
CommandDecoder commandDecoder = new CommandDecoder(input);
|
||||||
commandDecoder.CommandDecoder(input);
|
|
||||||
int binaryInput = Integer.parseInt(input);
|
|
||||||
System.out.println(binaryInput);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user