Я должен написать программу на C, которая принимает файл .asm, содержащий набор инструкций MIPS, а затем предоставляет диагностику того, что происходит во время каждого цикла. Что касается форматирования и т. Д., Мне не нужна помощь. Мне был предоставлен код, который охватывает это; однако я изо всех сил пытаюсь выяснить, как настроить регистры конвейера.MIPS Pipeline Simulator in C
У меня есть трубопровод IFID установить, и я думаю, что я трубопровод IDEX настроен правильно, но я не уверен, если я нахожусь на правильном пути, то regFile
массив в основном то, что я не уверен о, то state.regFile[(state.PC)/4];
делится на 4 из-за того, что адреса, предназначенные для имитации MIPS, выравниваются по словам, но я не знаю, имеет ли смысл то, что у меня в настоящее время имеет смысл.
Вот фрагмент моей основной функции.
Обратите внимание, что IFID
, IDEX
, EXMEM
, MEMWB
мои трубопроводы и являются структурами каждый из которых содержит информацию, необходимую для каждого трубопровода.
void run(){
stateType state; /* Contains the state of the entire pipeline before the cycle executes */
stateType newState; /* Contains the state of the entire pipeline after the cycle executes */
initState(&state); /* Initialize the state of the pipeline */
while (1) {
printState(&state);
/* If a halt instruction is entering its WB stage, then all of the legitimate */
/* instruction have completed. Print the statistics and exit the program. */
if (get_opcode(state.MEMWB.instr) == HALT) {
printf("Total number of cycles executed: %d\n", state.cycles);
/* Remember to print the number of stalls, branches, and mispredictions! */
exit(0);
}
newState = state; /* Start by making newState a copy of the state before the cycle */
newState.cycles++;
/* Modify newState stage-by-stage below to reflect the state of the pipeline after the cycle has executed */
/* --------------------- IF stage --------------------- */
/* Setting IFIDs instruction equal to the instruction found at address state.PC*/
newState.IFID.instr = state.instMem[(state.PC)/4];
/* Setting IFID's PCPlus4 to state.PC + 4 */
newState.IFID.PCPlus4 = state.PC + 4;
/* Update PC */
newState.PC = state.PC + 4;
/* --------------------- ID stage --------------------- */
newState.IDEX.instr = state.instMem[(state.PC)/4];
newState.IDEX.PCPlus4 = state.PC + 8;
newState.IDEX.readData1 = state.regFile[(state.PC)/4];
newState.IDEX.readData2 = state.regFile[(state.PC)/4];
newState.IDEX.immed = state.regFile[(state.PC)/4];
newState.IDEX.rsReg = state.regFile[(state.PC)/4];
newState.IDEX.rtReg = state.regFile[(state.PC)/4];
newState.IDEX.rdReg = state.regFile[(state.PC)/4];
newState.IDEX.branchTarget = state.regFile[(state.PC)/4];
/* --------------------- EX stage --------------------- */
newState.EXMEM.instr = state.instrMem[(state.PC)/4];
newState.EXMEM.PCPlus4 = state.PC + 12;
/* --------------------- MEM stage --------------------- */
/* --------------------- WB stage --------------------- */
state = newState; /* The newState now becomes the old state before we execute the next cycle */
}
}