Question: using any java coding language Implement a Java version of the ALU from our CPU that we've been building in class. Submit it on codepost.io.




Implement a Java version of the ALU from our CPU that we've been building in class. Submit it on codepost.io. The class should be named ALU. It should have a public static method called "doOperation" with signature: public static int doOperation(int op, int r2, int r3) In our instruction set (OurISA.txt), we have a list of operations which should be supported by our ALU. These are coded from 0000 through 1101, which correspond to integers 0 through 13. do Operation should do the appropriate operation from the list based on which value is passed as op and return the result of that operation on the input values. That is, if op is 0, then it should do operation 0000 which is subtraction and thus it should return r2-r3. If it is passed an invalid operation, the method is allowed to return anything it wants. There are tests on codepost.io for class and method name and then one test for each of the different operations. Shift and rotate operations will always have an r3 value between 0 and 31 inclusive. Any other operations can be passed any value for r2 and r3. There are tests on codepost.io for class and method name and then one test for each of the different operations. Shift and rotate operations will always have an r3 value between 0 and 31 inclusive. Any other operations can be passed any value for r2 and r3. Notes: 1) This should probably be implemented via a large if/elseiffelseif statement or a switch statement. 2) Some operations only work on a single value. These operations should operate on r2, not r3. 3) The right shift is an unsigned right shift which is the same as the >>> operator rather than >> 4) Please note that there are Java operators for most of the required operators. Check the bitwise operators slides (01 bits.pdf ) if you need a reminder of operators for shifting, bitwise and, or, not, and xor. 5) There is no built-in rotate operator in Java, but it can be implemented as follows: Left rotate: (rotate number v by b bits to the left) (v b) | (v >>> (32 - b)) Right rotate: (rotate number v by b bits to the right) (v >>> b) (v >> operator rather than >> 4) Please note that there are Java operators for most of the required operators. Check the bitwise operators slides (01 bits.pdf) if you need a reminder of operators for shifting, bitwise and, or, not, and xor. 5) There is no built-in rotate operator in Java, but it can be implemented as follows: Left rotate: (rotate number v by b bits to the left) (v b) | (v >>> (32 - b)) Right rotate: (rotate number v by b bits to the right) (v >>> b) (v
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
