Register.cpp 814 Bytes
Newer Older
jhe's avatar
lab3  
jhe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "Register.hpp"
#include <string>

std::string Reg::print() const {
    if (id == 0) {
        return "$zero";
    }
    if (id == 1) {
        return "$ra";
    }
    if (id == 2) {
        return "$tp";
    }
    if (id == 3) {
        return "$sp";
    }
    if (4 <= id and id <= 11) {
        return "$a" + std::to_string(id - 4);
    }
    if (12 <= id and id <= 20) {
        return "$t" + std::to_string(id - 12);
    }
    if (id == 22) {
        return "$fp";
    }
    assert(false);
}

std::string FReg::print() const {

    if (0 <= id and id <= 7) {
        return "$fa" + std::to_string(id);
    }
    if (8 <= id and id <= 23) {
        return "$ft" + std::to_string(id - 8);
    }
    if (24 <= id and id <= 31) {
        return "$fs" + std::to_string(id - 24);
    }
    assert(false);
}