Below is a java code for a class in a project to simulate MIPS instruction execution. I pretty much have most of all else but i am stuck on this one. Please read the commentary and help me figure out the code i need to put in for the decoder function. I need to implement method decode() in class Utils. This decodes hexadecimal command (0xafb2001c) into real command (add $1, $2, $3). Please give commentary if possible
package simulator;
/** * Class Utils contains the various utility functions used by other classes. The most * import one is decode(String hexcommand), which turns commands in hexadecimal into * readable format. * */ public class Utils { public static String strip0x(String s){ if (s.startsWith("0x")) return s.substring(2); return s; }
public static int parseNumber(String s){ //System.out.println("Trying to parse:"+s); if (s.startsWith("0x")) return Integer.valueOf(s.substring(2),16); return Integer.valueOf(s,10); }
/** * Given a hexadecimal command, return a command in readable assembly language. * @param hexcommand * @return */ public static String decoder(String hexcommand){ String command="";
return command; } }
This conversation is currently closed to new comments.
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Simulating MIPS instruction execution in java
command (0xafb2001c) into real command (add $1, $2, $3). Please give commentary if possible
package simulator;
/**
* Class Utils contains the various utility functions used by other classes. The most
* import one is decode(String hexcommand), which turns commands in hexadecimal into
* readable format.
*
*/
public class Utils {
public static String strip0x(String s){
if (s.startsWith("0x")) return s.substring(2);
return s;
}
public static int parseNumber(String s){
//System.out.println("Trying to parse:"+s);
if (s.startsWith("0x")) return Integer.valueOf(s.substring(2),16);
return Integer.valueOf(s,10);
}
/**
* Given a hexadecimal command, return a command in readable assembly language.
* @param hexcommand
* @return
*/
public static String decoder(String hexcommand){
String command="";
return command;
}
}