public void RvConsoleAction(InstructionPayload payload) { /* * The rv program supports the following non-RISC-V instructions: * * funct7 * * halt halt 0 * nl output newline to display 1 * dout reg output reg in decimal to display 2 * udout reg output reg in unsigned decimal to display 3 * hout reg output reg in hex to display 4 * aout reg output ASCII character in reg to display 5 * sout reg display string reg points to 6 * din reg input dec number from keyboard into reg 7 * hin reg input hex number from keyboard into reg 8 * ain reg input character from keyboard into reg 9 * sin reg like sout but for input a * m display memory b * x display registers c * s display stack d * bp software breakpoint e * ddout reg doubleword (i.e., 64 bits) decimal out f * dudout reg doubleword (i.e., 64 bits) unsigned dec out 10 * dhout reg doubleword (i.e., 64 bits) hex out 11 */ var rd = payload.Rd; var rs1 = payload.Rs1; var rs2 = payload.Rs2; var f3 = payload.Funct3; var f7 = payload.Funct7; var rs1ValueSigned = register.ReadSignedInt(rs1); var rs1ValueUnsigned = register.ReadSignedInt(rs1); int result = 0; Logger.Info("Opcode RV : rd = {rd}, rs1 = {rs1}, rs2 = {rs2}, f3 = {f3}, f7 = {f7}", rd, rs1, rs2, f3, f7); if (f7 == 0x01) { // nl output newline to display Console.WriteLine(); } if (f7 == 0x02) { // dout reg output reg in decimal to display Console.Write(rs1ValueSigned); } if (f7 == 0x03) { // udout reg output reg in unsigned decimal to display Console.Write(rs1ValueUnsigned); } if (f7 == 0x04) { // hout reg output reg in hex to display Console.WriteLine("{0:X}", rs1ValueUnsigned); } if (f7 == 0x05) { // aout reg output ASCII character in reg to display } if (f7 == 0x06) { // sout reg display string reg points to } if (f7 == 0x07) { // din reg input dec number from keyboard into reg Console.WriteLine("Enter dec number : "); var decValue = Console.ReadLine(); result = Int32.Parse(decValue); register.WriteSignedInt(rd, result); } if (f7 == 0x08) { // hin reg input hex number from keyboard into reg Console.WriteLine("Enter hex number : "); var hexValue = Console.ReadLine(); result = Int32.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); register.WriteSignedInt(rd, result); } if (f7 == 0x09) { // ain reg input character from keyboard into reg } if (f7 == 0x0A) { // sin reg like sout but for input } if (f7 == 0x0B) { // m display memory } if (f7 == 0x0C) { // x display registers var register = GetRegisterStates(); Console.WriteLine(register); } if (f7 == 0x0D) { // s display stack } if (f7 == 0x0E) { // bp software breakpoint } if (f7 == 0x0F) { // ddout reg doubleword (i.e., 64 bits) decimal out } if (f7 == 0x10) { // dudout reg doubleword (i.e., 64 bits) unsigned dec out } if (f7 == 0x11) { // dhout reg doubleword (i.e., 64 bits) hex out } }