From 908b7e965de42bb341f0093d1d9be120c7ed0260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A0rius=20Mont=C3=B3n?= Date: Mon, 8 Nov 2021 09:25:36 +0100 Subject: [PATCH] Better output, change registers to unsigned int as base. Should be uint32_t? --- inc/Registers.h | 2 +- src/Registers.cpp | 131 +++++++++++++++++++++++----------------------- 2 files changed, 67 insertions(+), 66 deletions(-) diff --git a/inc/Registers.h b/inc/Registers.h index a1438f9..7b3c43b 100644 --- a/inc/Registers.h +++ b/inc/Registers.h @@ -245,7 +245,7 @@ private: /** * bank of registers (32 regs of 32bits each) */ - std::array register_bank = { {0} }; + std::array register_bank = { {0} }; /** * Program counter (32 bits width) diff --git a/src/Registers.cpp b/src/Registers.cpp index 6e1da72..7e47854 100644 --- a/src/Registers.cpp +++ b/src/Registers.cpp @@ -24,79 +24,80 @@ Registers::Registers() { void Registers::dump() { std::cout << "************************************" << std::endl; std::cout << "Registers dump" << std::dec << std::endl; - std::cout << "x0 (zero): " << std::right << std::setw(11) - << register_bank[0]; - std::cout << " x1 (ra): " << std::right << std::setw(11) - << register_bank[1]; - std::cout << " x2 (sp): " << std::right << std::setw(11) - << register_bank[2]; - std::cout << " x3 (gp): " << std::right << std::setw(11) - << register_bank[3] << std::endl; + std::cout << std::setfill('0') << std::uppercase; + std::cout << "x0 (zero): 0x" << std::right << std::setw(8) + << std::hex << register_bank[0]; + std::cout << " x1 (ra): 0x" << std::right << std::setw(8) + << std::hex << register_bank[1]; + std::cout << " x2 (sp): 0x" << std::right << std::setw(8) + << std::hex << register_bank[2]; + std::cout << " x3 (gp): 0x" << std::right << std::setw(8) + << std::hex << register_bank[3] << std::endl; - std::cout << "x4 (tp): " << std::right << std::setw(11) - << register_bank[4]; - std::cout << " x5 (t0): " << std::right << std::setw(11) - << register_bank[5]; - std::cout << " x6 (t1): " << std::right << std::setw(11) - << register_bank[6]; - std::cout << " x7 (t2): " << std::right << std::setw(11) - << register_bank[7] << std::endl; + std::cout << "x4 (tp): 0x" << std::right << std::setw(8) + << std::hex << register_bank[4]; + std::cout << " x5 (t0): 0x" << std::right << std::setw(8) + << std::hex << register_bank[5]; + std::cout << " x6 (t1): 0x" << std::right << std::setw(8) + << std::hex << register_bank[6]; + std::cout << " x7 (t2): 0x" << std::right << std::setw(8) + << std::hex << register_bank[7] << std::endl; - std::cout << "x8 (s0/fp): " << std::right << std::setw(11) - << register_bank[8]; - std::cout << " x9 (s1): " << std::right << std::setw(11) - << register_bank[9]; - std::cout << " x10 (a0): " << std::right << std::setw(11) - << register_bank[10]; - std::cout << " x11 (a1): " << std::right << std::setw(11) - << register_bank[11] << std::endl; + std::cout << "x8 (s0/fp): 0x" << std::right << std::setw(8) + << std::hex << register_bank[8]; + std::cout << " x9 (s1): 0x" << std::right << std::setw(8) + << std::hex << register_bank[9]; + std::cout << " x10 (a0): 0x" << std::right << std::setw(8) + << std::hex << register_bank[10]; + std::cout << " x11 (a1): 0x" << std::right << std::setw(8) + << std::hex << register_bank[11] << std::endl; - std::cout << "x12 (a2): " << std::right << std::setw(11) - << register_bank[12]; - std::cout << " x13 (a3): " << std::right << std::setw(11) - << register_bank[13]; - std::cout << " x14 (a4): " << std::right << std::setw(11) - << register_bank[14]; - std::cout << " x15 (a5): " << std::right << std::setw(11) - << register_bank[15] << std::endl; + std::cout << "x12 (a2): 0x" << std::right << std::setw(8) + << std::hex << register_bank[12]; + std::cout << " x13 (a3): 0x" << std::right << std::setw(8) + << std::hex << register_bank[13]; + std::cout << " x14 (a4): 0x" << std::right << std::setw(8) + << std::hex << register_bank[14]; + std::cout << " x15 (a5): 0x" << std::right << std::setw(8) + << std::hex << register_bank[15] << std::endl; - std::cout << "x16 (a6): " << std::right << std::setw(11) - << register_bank[16]; - std::cout << " x17 (a7): " << std::right << std::setw(11) - << register_bank[17]; - std::cout << " x18 (s2): " << std::right << std::setw(11) - << register_bank[18]; - std::cout << " x19 (s3): " << std::right << std::setw(11) - << register_bank[19] << std::endl; + std::cout << "x16 (a6): 0x" << std::right << std::setw(8) + << std::hex << register_bank[16]; + std::cout << " x17 (a7): 0x" << std::right << std::setw(8) + << std::hex << register_bank[17]; + std::cout << " x18 (s2): 0x" << std::right << std::setw(8) + << std::hex << register_bank[18]; + std::cout << " x19 (s3): 0x" << std::right << std::setw(8) + << std::hex << register_bank[19] << std::endl; - std::cout << "x20 (s4): " << std::right << std::setw(11) - << register_bank[20]; - std::cout << " x21 (s5): " << std::right << std::setw(11) - << register_bank[21]; - std::cout << " x22 (s6): " << std::right << std::setw(11) - << register_bank[22]; - std::cout << " x23 (s7): " << std::right << std::setw(11) - << register_bank[23] << std::endl; + std::cout << "x20 (s4): 0x" << std::right << std::setw(8) + << std::hex << register_bank[20]; + std::cout << " x21 (s5): 0x" << std::right << std::setw(8) + << std::hex << register_bank[21]; + std::cout << " x22 (s6): 0x" << std::right << std::setw(8) + << std::hex << register_bank[22]; + std::cout << " x23 (s7): 0x" << std::right << std::setw(8) + << std::hex << register_bank[23] << std::endl; - std::cout << "x24 (s8): " << std::right << std::setw(11) - << register_bank[24]; - std::cout << " x25 (s9): " << std::right << std::setw(11) - << register_bank[25]; - std::cout << " x26 (s10): " << std::right << std::setw(11) - << register_bank[26]; - std::cout << " x27 (s11): " << std::right << std::setw(11) - << register_bank[27] << std::endl; + std::cout << "x24 (s8): 0x" << std::right << std::setw(8) + << std::hex << register_bank[24]; + std::cout << " x25 (s9): 0x" << std::right << std::setw(8) + << std::hex << register_bank[25]; + std::cout << " x26 (s10): 0x" << std::right << std::setw(8) + << std::hex << register_bank[26]; + std::cout << " x27 (s11): 0x" << std::right << std::setw(8) + << std::hex << register_bank[27] << std::endl; - std::cout << "x28 (t3): " << std::right << std::setw(11) - << register_bank[28]; - std::cout << " x29 (t4): " << std::right << std::setw(11) - << register_bank[29]; - std::cout << " x30 (t5): " << std::right << std::setw(11) - << register_bank[30]; - std::cout << " x31 (t6): " << std::right << std::setw(11) - << register_bank[31] << std::endl; + std::cout << "x28 (t3): 0x" << std::right << std::setw(8) + << std::hex << register_bank[28]; + std::cout << " x29 (t4): 0x" << std::right << std::setw(8) + << std::hex << register_bank[29]; + std::cout << " x30 (t5): 0x" << std::right << std::setw(8) + << std::hex << register_bank[30]; + std::cout << " x31 (t6): 0x" << std::right << std::setw(8) + << std::hex << register_bank[31] << std::endl; - std::cout << "PC: 0x" << std::hex << register_PC << std::dec << std::endl; + std::cout << "PC: 0x" << std::setw(8) << std::hex << register_PC << std::dec << std::endl; std::cout << "************************************" << std::endl; }