├── Documentation.docx ├── LICENSE ├── README.md ├── Tomasulo Simulator.exe ├── quick user manual.jpeg ├── source.cpp └── source.txt /Documentation.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BigWheel92/Tomasulo-Simulator/fc00dde66d83ce6a61ec37a5ef5de2c236684038/Documentation.docx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Saad Farooq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tomasulo-Simulator-in-C++-for-Windows 2 | 3 | The Tomasulo-Simulator-in-C++-for-Windows simulates the tomasulo computer hardware algorithm. it shows the state after each step of execution. The code currently runs on Windows platform because it uses Window.h library. 4 | 5 | The program requires an input file named "source.txt" which contains the information about: 6 | 1. the number of reservation stations for add/sub, mul/div. 7 | 2. the number of cycles of each instruction. 8 | 3. the total number of registers. 9 | 4. the instructions to execute using Tomasulo Simulator. 10 | 11 | A sample input file named "source.txt" is also present in the repository. 12 | -------------------------------------------------------------------------------- /Tomasulo Simulator.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BigWheel92/Tomasulo-Simulator/fc00dde66d83ce6a61ec37a5ef5de2c236684038/Tomasulo Simulator.exe -------------------------------------------------------------------------------- /quick user manual.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BigWheel92/Tomasulo-Simulator/fc00dde66d83ce6a61ec37a5ef5de2c236684038/quick user manual.jpeg -------------------------------------------------------------------------------- /source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | struct InstructionType; 10 | struct ReservationStation; 11 | struct Instruction; 12 | struct LoadBuffer; 13 | struct StoreBuffer; 14 | struct InstructionStatus; 15 | struct Tomasulo; 16 | 17 | 18 | /*Instruction Status has the information about when an instruction was issued, started its execution, finished its execution, 19 | and wrote back.*/ 20 | struct InstructionStatus 21 | { 22 | 23 | short issue; 24 | short executionStart; 25 | short executionComplete; 26 | short writeBack; 27 | 28 | short executionCyclesRemaining; 29 | InstructionStatus() 30 | { 31 | issue = executionStart = executionComplete = writeBack = executionCyclesRemaining= -1; 32 | } 33 | }; 34 | 35 | struct InstructionType 36 | { 37 | public: 38 | string static const MULTD; 39 | string static const SUBD; 40 | string static const ADDD; 41 | string static const DIVD; 42 | string static const LOAD; 43 | string static const BNE; 44 | string static const STORE; 45 | }; 46 | 47 | string const InstructionType::MULTD = "MUL"; 48 | string const InstructionType::SUBD = "SUB"; 49 | string const InstructionType::ADDD = "ADD"; 50 | string const InstructionType::DIVD = "DIV"; 51 | 52 | string const InstructionType::LOAD="LOAD"; 53 | string const InstructionType::BNE="BNE"; 54 | string const InstructionType::STORE = "STORE"; 55 | 56 | struct ReservationStationType 57 | { 58 | static string const ADDD; 59 | static string const MULTD; 60 | }; 61 | 62 | string const ReservationStationType::ADDD = "ADD"; 63 | string const ReservationStationType::MULTD = "MUL"; 64 | 65 | struct LoadStoreBufferType 66 | { 67 | static string const LOAD; 68 | static string const STORE; 69 | }; 70 | 71 | string const LoadStoreBufferType::LOAD = "LOAD"; 72 | string const LoadStoreBufferType::STORE = "STORE"; 73 | 74 | 75 | struct Instruction 76 | { 77 | string instructionType; 78 | string Rd; 79 | string Rs; 80 | string Rt; 81 | int immediateOffset; //used only for i-type instructions 82 | InstructionStatus instructionStatus; 83 | 84 | Instruction() 85 | { 86 | instructionType = Rd = Rs = Rt = ""; 87 | immediateOffset = -1; 88 | } 89 | }; 90 | 91 | struct RegisterStatus 92 | { 93 | string registerName; 94 | string writingUnit; 95 | 96 | }; 97 | 98 | struct ReservationStation 99 | { 100 | string name; 101 | bool isBusy; 102 | string instructionType; 103 | string Vj; 104 | string Vk; 105 | string Qj; 106 | string Qk; 107 | 108 | Instruction *instruction; //the pointer to the current instruction being executed 109 | 110 | ReservationStation() 111 | { 112 | isBusy = false; 113 | instruction = nullptr; 114 | } 115 | 116 | 117 | }; 118 | 119 | struct LoadStoreBuffer 120 | { 121 | string name; 122 | bool isBusy; 123 | string address; 124 | 125 | LoadStoreBuffer() 126 | { 127 | name = ""; 128 | isBusy = false; 129 | address = ""; 130 | instruction = nullptr; 131 | fu = ""; 132 | } 133 | 134 | string fu; 135 | Instruction *instruction; 136 | }; 137 | 138 | void gotoxy(short, short); 139 | 140 | struct Tomasulo 141 | { 142 | 143 | string reason; 144 | int currentCycleNumber; 145 | LoadStoreBuffer *loadBuffers; 146 | LoadStoreBuffer *storeBuffers; 147 | ReservationStation *addSubReservationStations; 148 | ReservationStation *multDivReservationStations; 149 | RegisterStatus *registerStatus; 150 | 151 | 152 | int totalLoadBuffers; 153 | int totalStoreBuffers; 154 | int totalAddSubReservationStations; 155 | int totalMultDivReservationStations; 156 | 157 | int totalRegisters; 158 | Instruction* instructions; 159 | int totalInstructions; 160 | 161 | //the following fields tell us how many cycles does each instruction type take in execution stage. 162 | int totalLoadStoreCycles; 163 | int totalAddSubCycles; 164 | int totalMultCylcles; 165 | int totalDivCycles; 166 | 167 | 168 | //load instructions and other information from the file. 169 | void loadDataFromFile(string fileName) 170 | { 171 | 172 | if (fileName == "") 173 | { 174 | fileName = "source.txt"; 175 | } 176 | 177 | ifstream read; 178 | read.open(fileName); 179 | if (read.is_open() == false) 180 | { 181 | cout << "File could not open!" << endl; 182 | system("pause"); 183 | exit(EXIT_FAILURE); 184 | } 185 | 186 | string data; 187 | while (read.peek() != '#') 188 | read.ignore(); 189 | 190 | getline(read, data); //ignore the first line; 191 | //cout << data << endl; 192 | bool loadDone = false, 193 | storeDone = false, 194 | addSubDone = false, 195 | multDivDone = false; 196 | 197 | bool exit_ = false; 198 | 199 | //read information about the number of buffers/ reservation stations 200 | for (int i = 0; i < 4; i++) 201 | { 202 | read >> data; 203 | // cout << data << " "; 204 | if (_strcmpi(data.c_str(), "Add_Sub_Reservation_Stations") == 0) 205 | { 206 | addSubDone = true; 207 | read >> this->totalAddSubReservationStations; 208 | //cout << this->totalAddSubReservationStations << endl; 209 | } 210 | 211 | else if (_strcmpi(data.c_str(), "Mul_Div_Reservation_Stations") == 0) 212 | { 213 | multDivDone = true; 214 | read >> this->totalMultDivReservationStations; 215 | // cout << this->totalMultDivReservationStations << endl; 216 | } 217 | 218 | else if (_strcmpi(data.c_str(), "Load_Buffers") == 0) 219 | { 220 | loadDone = true; 221 | read >> this->totalLoadBuffers; 222 | // cout << this->totalLoadBuffers << endl; 223 | } 224 | 225 | else if (_strcmpi(data.c_str(), "Store_Buffers") == 0) 226 | { 227 | storeDone = true; 228 | read >> this->totalStoreBuffers; 229 | // cout << this->totalStoreBuffers << endl; 230 | } 231 | 232 | } 233 | if (!storeDone) 234 | { 235 | cout << "-> Information about the number of store buffers missing." << endl; 236 | exit_ = true; 237 | 238 | } 239 | else if (!loadDone) 240 | { 241 | cout << "-> Informaton about the number of load buffers missing." << endl; 242 | exit_ = true; 243 | } 244 | else if (!multDivDone) 245 | { 246 | cout << "-> Information about the number of Mult Div Reservation Stations missing" << endl; 247 | exit_ = true; 248 | } 249 | 250 | else if (!addSubDone) 251 | { 252 | cout << "-> Information about the number of Add Sub Reservation Stations missing." << endl; 253 | exit_ = true; 254 | } 255 | 256 | 257 | 258 | //reading information about cycle instructions 259 | bool multCyclesDone = false, 260 | divCyclesDones = false, 261 | addSubCyclesDone = false, 262 | loadStoreCyclesDone = false; 263 | 264 | while (read.peek() != '#') 265 | read.ignore(); 266 | 267 | getline(read,data); //ignore the line containing comments 268 | //cout << data << endl; 269 | for (int i = 0; i < 4; i++) 270 | { 271 | read >> data; 272 | //cout << data << " "; 273 | if (_strcmpi(data.c_str(), "Add_Sub_Cycles") == 0) 274 | { 275 | 276 | read >> this->totalAddSubCycles; 277 | // cout << this->totalAddSubCycles << endl; 278 | addSubCyclesDone = true; 279 | } 280 | 281 | else if (_strcmpi(data.c_str(), "Mul_Cycles") == 0) 282 | { 283 | read >> this->totalMultCylcles; 284 | // cout << this->totalMultCylcles << endl; 285 | multCyclesDone = true; 286 | } 287 | else if (_strcmpi(data.c_str(), "Load_Store_Cycles") == 0) 288 | { 289 | read >> this->totalLoadStoreCycles; 290 | // cout << this->totalLoadStoreCycles << endl; 291 | loadStoreCyclesDone = true; 292 | } 293 | else if (_strcmpi(data.c_str(), "Div_Cycles") == 0) 294 | { 295 | read >> this->totalDivCycles; 296 | // cout << this->totalDivCycles << endl; 297 | divCyclesDones = true; 298 | } 299 | 300 | } 301 | 302 | if (!addSubCyclesDone) 303 | { 304 | cout << "-> Information about the number of add Sub Cycles missing."; 305 | exit_ = true; 306 | } 307 | 308 | if (!multCyclesDone) 309 | { 310 | cout << "-> Information about the number of mul cycles missing." << endl; 311 | exit_ = true; 312 | } 313 | else if (!divCyclesDones) 314 | { 315 | cout << "-> Information about the number of div cycles missing." << endl; 316 | exit_ = true; 317 | } 318 | else if (!loadStoreCyclesDone) 319 | { 320 | cout << "-> Information about the number of load store cycles missing." << endl; 321 | exit_ = true; 322 | } 323 | 324 | if (exit_ == true) 325 | { 326 | system("pause"); 327 | exit(EXIT_FAILURE); 328 | 329 | } 330 | 331 | this->loadBuffers = new LoadStoreBuffer[this->totalLoadBuffers]; 332 | for (int i = 0; i < totalLoadBuffers; i++) 333 | { 334 | char num[10]; 335 | _itoa_s(i, num, 10); 336 | this->loadBuffers[i].name = LoadStoreBufferType::LOAD; 337 | this->loadBuffers[i].name.append(num); 338 | } 339 | 340 | this->storeBuffers = new LoadStoreBuffer[this->totalStoreBuffers]; 341 | for (int i = 0; i < totalStoreBuffers; i++) 342 | { 343 | char num[10]; 344 | _itoa_s(i, num, 10); 345 | // cout << "NUM: " << num << endl; 346 | // system("pause"); 347 | this->storeBuffers[i].name = LoadStoreBufferType::STORE; 348 | this->storeBuffers[i].name.append(num); 349 | //cout << this->storeBuffers[i].name; 350 | } 351 | 352 | this->addSubReservationStations = new ReservationStation[this->totalAddSubReservationStations]; 353 | for (int i = 0; i < this->totalAddSubReservationStations; i++) 354 | { 355 | char num[10]; 356 | _itoa_s(i, num, 10); 357 | this->addSubReservationStations[i].name = ReservationStationType::ADDD; 358 | this->addSubReservationStations[i].name.append(num); 359 | } 360 | 361 | this->multDivReservationStations = new ReservationStation[this->totalMultDivReservationStations]; 362 | for (int i = 0; i < this->totalMultDivReservationStations; i++) 363 | { 364 | char num[10]; 365 | _itoa_s(i, num, 10); 366 | this->multDivReservationStations[i].name = ReservationStationType::MULTD; 367 | this->multDivReservationStations[i].name.append(num); 368 | } 369 | 370 | 371 | 372 | while (read.peek() != '#') 373 | read.ignore(); 374 | 375 | //reading information about the number of registers; 376 | getline(read, data); 377 | read >> data; 378 | read >> this->totalRegisters; 379 | this->registerStatus = new RegisterStatus[totalRegisters]; 380 | 381 | for (int i = 0; i < totalRegisters; i++) 382 | { 383 | this->registerStatus[i].registerName = "F"; 384 | char num[10]; 385 | _itoa_s(i, num, 10); 386 | this->registerStatus[i].registerName.append(num); 387 | } 388 | 389 | 390 | //reading instructions 391 | while (read.peek() != '#') 392 | read.ignore(); 393 | 394 | getline(read, data); //ignore the first line 395 | read >> this->totalInstructions; 396 | this->instructions = new Instruction[this->totalInstructions]; 397 | 398 | for (int i = 0; i < totalInstructions; i++) 399 | { 400 | string instruction; 401 | read >> instruction; 402 | if (_strcmpi(instruction.c_str(), InstructionType::ADDD.c_str()) == 0 ) 403 | { 404 | this->instructions[i].instructionType = InstructionType::ADDD; 405 | read >> this->instructions[i].Rd; 406 | read >> this->instructions[i].Rs; 407 | read >> this->instructions[i].Rt; 408 | } 409 | 410 | else if (_strcmpi(instruction.c_str(), InstructionType::SUBD.c_str()) == 0) 411 | { 412 | this->instructions[i].instructionType = InstructionType::SUBD; 413 | read >> this->instructions[i].Rd; 414 | read >> this->instructions[i].Rs; 415 | read >> this->instructions[i].Rt; 416 | 417 | } 418 | else if (_strcmpi(instruction.c_str(), InstructionType::MULTD.c_str()) == 0) 419 | { 420 | this->instructions[i].instructionType = InstructionType::MULTD; 421 | read >> this->instructions[i].Rd; 422 | read >> this->instructions[i].Rs; 423 | read >> this->instructions[i].Rt; 424 | 425 | } 426 | else if (_strcmpi(instruction.c_str(), InstructionType::DIVD.c_str()) == 0) 427 | { 428 | this->instructions[i].instructionType = InstructionType::DIVD; 429 | read >> this->instructions[i].Rd; 430 | read >> this->instructions[i].Rs; 431 | read >> this->instructions[i].Rt; 432 | 433 | } 434 | 435 | else if (_strcmpi(instruction.c_str(), InstructionType::LOAD.c_str())==0) 436 | { 437 | this->instructions[i].instructionType = InstructionType::LOAD; 438 | read >> this->instructions[i].Rt; 439 | read >> this->instructions[i].immediateOffset; 440 | read >> this->instructions[i].Rs; 441 | } 442 | 443 | else if (_strcmpi(instruction.c_str(), InstructionType::STORE.c_str()) == 0) 444 | { 445 | this->instructions[i].instructionType = InstructionType::STORE; 446 | read >> this->instructions[i].Rt; 447 | read >> this->instructions[i].immediateOffset; 448 | read >> this->instructions[i].Rs; 449 | 450 | } 451 | 452 | 453 | 454 | } 455 | 456 | 457 | 458 | } 459 | int findFreeReservationStationForStoreInstruction() 460 | { 461 | for (int i = 0; i < totalStoreBuffers; i++) 462 | { 463 | if (storeBuffers[i].isBusy == false) 464 | return i; 465 | } 466 | 467 | return -1; 468 | } 469 | 470 | int findFreeReservationStationforAddSubInstruction() 471 | { 472 | for (int i = 0; i < totalAddSubReservationStations; i++) 473 | { 474 | if (addSubReservationStations[i].isBusy == false) 475 | { 476 | return i; 477 | } 478 | } 479 | return -1; 480 | } 481 | 482 | int findFreeReservationStationforMultDivInstruction() 483 | { 484 | for (int i = 0; i < totalMultDivReservationStations; i++) 485 | { 486 | if (multDivReservationStations[i].isBusy == false) 487 | { 488 | return i; 489 | } 490 | } 491 | return -1; 492 | } 493 | int findFreeRservationStationForLoadInstruction() 494 | { 495 | for (int i = 0; i loadBuffers[i].isBusy == false) 511 | continue; 512 | 513 | if (this->loadBuffers[i].fu == name) 514 | { 515 | this->loadBuffers[i].fu = ""; 516 | } 517 | } 518 | 519 | for (int i = 0; i < totalStoreBuffers; i++) 520 | { 521 | if (this->storeBuffers[i].isBusy == false) 522 | continue; 523 | 524 | if (this->storeBuffers[i].fu == name) 525 | { 526 | this->storeBuffers[i].fu = ""; 527 | } 528 | } 529 | 530 | for (int i = 0; i < totalAddSubReservationStations; i++) 531 | { 532 | if (this->addSubReservationStations[i].Qj == name) 533 | { 534 | this->addSubReservationStations[i].Qj = ""; 535 | this->addSubReservationStations[i].Vj = val; 536 | 537 | } 538 | 539 | if (this->addSubReservationStations[i].Qk == name) 540 | { 541 | this->addSubReservationStations[i].Qk = ""; 542 | this->addSubReservationStations[i].Vk = val; 543 | } 544 | } 545 | 546 | for (int i = 0; i < totalMultDivReservationStations; i++) 547 | { 548 | if (this->multDivReservationStations[i].Qj == name) 549 | { 550 | this->multDivReservationStations[i].Qj = ""; 551 | this->multDivReservationStations[i].Vj = val; 552 | 553 | } 554 | 555 | if (this->multDivReservationStations[i].Qk == name) 556 | { 557 | this->multDivReservationStations[i].Qk = ""; 558 | this->multDivReservationStations[i].Vk = val; 559 | } 560 | } 561 | } 562 | 563 | 564 | int issueInstruction(int currentInstructionNumberToBeIssued) 565 | { 566 | int bufferNo; 567 | char num[10]; 568 | _itoa_s(currentInstructionNumberToBeIssued, num, 10); 569 | 570 | if (currentInstructionNumberToBeIssued < totalInstructions) 571 | { 572 | if (instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::LOAD) 573 | { 574 | bufferNo = findFreeRservationStationForLoadInstruction(); 575 | 576 | if (bufferNo == -1) 577 | { 578 | 579 | reason += "-> The instruction Number: "; 580 | reason.append(num); 581 | reason+=" has not been issued due to the structural hazard.\n"; 582 | 583 | return -1; 584 | } 585 | else 586 | { 587 | loadBuffers[bufferNo].isBusy = true; 588 | loadBuffers[bufferNo].instruction = &this->instructions[currentInstructionNumberToBeIssued]; 589 | loadBuffers[bufferNo].address = this->instructions[currentInstructionNumberToBeIssued].Rs; 590 | char offset[10]; 591 | _itoa_s(this->instructions[currentInstructionNumberToBeIssued].immediateOffset, offset, 10); 592 | loadBuffers[bufferNo].address += " + "; 593 | loadBuffers[bufferNo].address.append(offset); 594 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.issue = currentCycleNumber; 595 | reason += "-> The instruction number: "; 596 | reason.append(num); 597 | reason += " has been issued at Load Buffer= "+loadBuffers[bufferNo].name+"\n"; 598 | 599 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.executionCyclesRemaining = this->totalLoadStoreCycles; 600 | //RAW hazard check 601 | int regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rt.c_str()[1]);//extract register number fro register name 602 | this->loadBuffers[bufferNo].fu = this->registerStatus[regNumber].writingUnit; 603 | 604 | 605 | //set the register status of register which is going to be written by this load instruction 606 | this->registerStatus[regNumber].writingUnit = loadBuffers[bufferNo].name; 607 | 608 | 609 | 610 | 611 | } 612 | 613 | } 614 | 615 | 616 | else if (instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::STORE) 617 | { 618 | bufferNo = findFreeReservationStationForStoreInstruction(); 619 | 620 | if (bufferNo == -1) 621 | { 622 | reason += "-> The instruction number: "; 623 | reason.append(num); 624 | reason += " has not been issued due to the structural hazard.\n"; 625 | return -1; 626 | } 627 | else 628 | { 629 | 630 | reason += "-> The instruction number: "; 631 | reason.append(num); 632 | reason += " has been issued at Store Buffer= " + storeBuffers[bufferNo].name + "\n"; 633 | 634 | this->storeBuffers[bufferNo].isBusy = true; 635 | 636 | //checking RAW hazard 637 | int regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rt.c_str()[1]); 638 | this->storeBuffers[bufferNo].fu = this->registerStatus[regNumber].writingUnit; 639 | 640 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.executionCyclesRemaining=this->totalLoadStoreCycles; 641 | 642 | storeBuffers[bufferNo].isBusy = true; 643 | storeBuffers[bufferNo].instruction = &this->instructions[currentInstructionNumberToBeIssued]; 644 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.issue = currentCycleNumber; 645 | storeBuffers[bufferNo].address = this->instructions[currentInstructionNumberToBeIssued].Rs; 646 | char offset[10]; 647 | _itoa_s(this->instructions[currentInstructionNumberToBeIssued].immediateOffset, offset, 10); 648 | storeBuffers[bufferNo].address += " + "; 649 | storeBuffers[bufferNo].address.append(offset); 650 | 651 | 652 | 653 | 654 | } 655 | } 656 | 657 | else if (instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::ADDD || instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::SUBD) 658 | { 659 | int bufferNo = findFreeReservationStationforAddSubInstruction(); 660 | 661 | 662 | if (bufferNo == -1) 663 | { 664 | 665 | reason += "-> The instruction No: "; 666 | reason.append(num); 667 | reason += " cannot be issued due to structural Hazard!\n"; 668 | return -1; 669 | } 670 | 671 | else 672 | { 673 | 674 | reason += "-> The instruction No: "; 675 | reason.append(num); 676 | reason += " has been issued at Reservation Station= "+addSubReservationStations[bufferNo].name+ "\n"; 677 | 678 | 679 | 680 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.executionCyclesRemaining = this->totalAddSubCycles; 681 | this->addSubReservationStations[bufferNo].instructionType = this->instructions[currentInstructionNumberToBeIssued].instructionType; 682 | this->addSubReservationStations[bufferNo].instruction = &this->instructions[currentInstructionNumberToBeIssued]; 683 | this->addSubReservationStations[bufferNo].isBusy = true; 684 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.issue = currentCycleNumber; 685 | 686 | 687 | //checking RAW hazard 688 | //RS 689 | int regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rs.c_str()[1]); 690 | 691 | this->addSubReservationStations[bufferNo].Qj = this->registerStatus[regNumber].writingUnit; 692 | 693 | //Rt 694 | regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rt.c_str()[1]); 695 | this->addSubReservationStations[bufferNo].Qk = this->registerStatus[regNumber].writingUnit; 696 | 697 | if (this->addSubReservationStations[bufferNo].Qj == "") 698 | { 699 | this->addSubReservationStations[bufferNo].Vj = "R(" + this->instructions[currentInstructionNumberToBeIssued].Rs + ")"; 700 | } 701 | 702 | if (this->addSubReservationStations[bufferNo].Qk == "") 703 | { 704 | this->addSubReservationStations[bufferNo].Vk = "R(" + this->instructions[currentInstructionNumberToBeIssued].Rt + ")"; 705 | } 706 | 707 | 708 | //setting register status 709 | regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rd.c_str()[1]); 710 | this->registerStatus[regNumber].writingUnit = this->addSubReservationStations[bufferNo].name; 711 | 712 | 713 | } 714 | } 715 | 716 | else if (instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::MULTD || instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::DIVD) 717 | { 718 | int bufferNo = findFreeReservationStationforMultDivInstruction(); 719 | char instructionNumberConversion[10]; 720 | _itoa_s(currentInstructionNumberToBeIssued, instructionNumberConversion, 10, 10); 721 | 722 | if (bufferNo == -1) 723 | { 724 | 725 | reason += "-> The instruction No: "; 726 | reason.append(instructionNumberConversion); 727 | reason += " cannot be issued due to structural Hazard!\n"; 728 | return -1; 729 | } 730 | 731 | else 732 | { 733 | 734 | reason += "-> The instruction No: "; 735 | reason.append(num); 736 | reason += " has been issued at Reservation Station= " + this->multDivReservationStations[bufferNo].name + "\n"; 737 | 738 | 739 | if (this->instructions[currentInstructionNumberToBeIssued].instructionType == InstructionType::MULTD) 740 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.executionCyclesRemaining = this->totalMultCylcles; 741 | else 742 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.executionCyclesRemaining = this->totalDivCycles; 743 | 744 | this->multDivReservationStations[bufferNo].instructionType = this->instructions[currentInstructionNumberToBeIssued].instructionType; 745 | this->multDivReservationStations[bufferNo].instruction = &this->instructions[currentInstructionNumberToBeIssued]; 746 | this->multDivReservationStations[bufferNo].isBusy = true; 747 | this->instructions[currentInstructionNumberToBeIssued].instructionStatus.issue = currentCycleNumber; 748 | 749 | 750 | //checking RAW hazard 751 | //RS 752 | int regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rs.c_str()[1]); 753 | 754 | this->multDivReservationStations[bufferNo].Qj = this->registerStatus[regNumber].writingUnit; 755 | 756 | //Rt 757 | regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rt.c_str()[1]); 758 | 759 | this->multDivReservationStations[bufferNo].Qk = this->registerStatus[regNumber].writingUnit; 760 | 761 | if (this->multDivReservationStations[bufferNo].Qj == "") 762 | { 763 | this->multDivReservationStations[bufferNo].Vj = "R(" + this->instructions[currentInstructionNumberToBeIssued].Rs + ")"; 764 | } 765 | 766 | if (this->multDivReservationStations[bufferNo].Qk == "") 767 | { 768 | 769 | 770 | this->multDivReservationStations[bufferNo].Vk = "R(" + this->instructions[currentInstructionNumberToBeIssued].Rt + ")"; 771 | 772 | 773 | } 774 | 775 | //setting register status 776 | regNumber = atoi(&this->instructions[currentInstructionNumberToBeIssued].Rd.c_str()[1]); 777 | 778 | this->registerStatus[regNumber].writingUnit = this->multDivReservationStations[bufferNo].name; 779 | 780 | } 781 | } 782 | 783 | 784 | } 785 | return 0; 786 | } 787 | 788 | void writeBack() 789 | { 790 | 791 | 792 | for (int i = 0; i < totalLoadBuffers; i++) 793 | { 794 | int static num = 1; 795 | 796 | if (this->loadBuffers[i].isBusy == false) 797 | continue; 798 | 799 | if (this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining != 0) 800 | continue; //the instruction is still executing 801 | 802 | if (this->loadBuffers[i].instruction->instructionStatus.executionComplete == currentCycleNumber) 803 | continue; //the instruction has completed execution in the current cycle, so it cannot be written in the current Cycle 804 | 805 | this->loadBuffers[i].instruction->instructionStatus.writeBack = currentCycleNumber; 806 | 807 | reason += "-> The instruction at Load Buffer= " + this->loadBuffers[i].name + " has written back.\n"; 808 | int regNum=atoi(&this->loadBuffers[i].instruction->Rt.c_str()[1]); 809 | if (this->registerStatus[regNum].writingUnit == this->loadBuffers[i].name) 810 | this->registerStatus[regNum].writingUnit = ""; 811 | 812 | this->loadBuffers[i].isBusy = false; 813 | this->loadBuffers[i].address = ""; 814 | this->loadBuffers[i].instruction = nullptr; 815 | 816 | char numChar[10]; 817 | _itoa_s(num, numChar, 10); 818 | string val = "M(A"; 819 | val.append(numChar); 820 | val += ")"; 821 | broadCastResult(val, this->loadBuffers[i].name); 822 | num++; 823 | } 824 | 825 | 826 | for (int i = 0; i < totalStoreBuffers; i++) 827 | { 828 | if (this->storeBuffers[i].isBusy == false) 829 | continue; 830 | 831 | if (this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining != 0) 832 | continue; //the instruction is still executing 833 | 834 | if (this->storeBuffers[i].instruction->instructionStatus.executionComplete == currentCycleNumber) 835 | continue; //the instruction has completed execution in the current cycle, so it cannot be written in the current Cycle 836 | 837 | reason += "-> The instruction at Store Buffer= " + this->storeBuffers[i].name + " has written back.\n"; 838 | this->storeBuffers[i].instruction->instructionStatus.writeBack = currentCycleNumber; 839 | this->storeBuffers[i].isBusy = false; 840 | this->storeBuffers[i].address = ""; 841 | this->storeBuffers[i].instruction = nullptr; 842 | //broadCastResult(); 843 | } 844 | 845 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// 846 | 847 | 848 | for (int i = 0; i < totalAddSubReservationStations; i++) 849 | { 850 | int static num = 1; 851 | 852 | if (this->addSubReservationStations[i].isBusy == false) 853 | continue; 854 | 855 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining != 0) 856 | continue; //the instruction is still executing 857 | 858 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionComplete == currentCycleNumber) 859 | continue; //the instruction has completed execution in the current cycle, so it cannot be written in the current Cycle 860 | 861 | this->addSubReservationStations[i].instruction->instructionStatus.writeBack = currentCycleNumber; 862 | reason += "-> The instruction at Reserrvation Station= " + this->addSubReservationStations[i].name + " has written back.\n"; 863 | 864 | int regNum = atoi(&this->addSubReservationStations[i].instruction->Rd.c_str()[1]); 865 | if (this->registerStatus[regNum].writingUnit == this->addSubReservationStations[i].name) 866 | this->registerStatus[regNum].writingUnit = ""; 867 | 868 | this->addSubReservationStations[i].isBusy = false; 869 | this->addSubReservationStations[i].instructionType = ""; 870 | this->addSubReservationStations[i].Qj = ""; 871 | this->addSubReservationStations[i].Qk = ""; 872 | this->addSubReservationStations[i].Vj = ""; 873 | this->addSubReservationStations[i].Vk = ""; 874 | this->addSubReservationStations[i].instruction = nullptr; 875 | 876 | char numChar[10]; 877 | _itoa_s(num, numChar, 10); 878 | string val = "V"; 879 | val.append(numChar); 880 | 881 | broadCastResult(val, this->addSubReservationStations[i].name); 882 | num++; 883 | } 884 | 885 | //////////////////////////////////////////////////////////////////////////////// 886 | 887 | for (int i = 0; i < totalMultDivReservationStations; i++) 888 | { 889 | int static num = 1; 890 | 891 | if (this->multDivReservationStations[i].isBusy == false) 892 | continue; 893 | 894 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining != 0) 895 | continue; //the instruction is still executing 896 | 897 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionComplete == currentCycleNumber) 898 | continue; //the instruction has completed execution in the current cycle, so it cannot be written in the current Cycle 899 | 900 | this->multDivReservationStations[i].instruction->instructionStatus.writeBack = currentCycleNumber; 901 | reason += "-> The instruction at Reserrvation Station= " + this->multDivReservationStations[i].name + " has written back.\n"; 902 | 903 | int regNum = atoi(&this->multDivReservationStations[i].instruction->Rd.c_str()[1]); 904 | if (this->registerStatus[regNum].writingUnit == this->multDivReservationStations[i].name) 905 | this->registerStatus[regNum].writingUnit = ""; 906 | 907 | this->multDivReservationStations[i].isBusy = false; 908 | this->multDivReservationStations[i].instructionType = ""; 909 | this->multDivReservationStations[i].Qj = ""; 910 | this->multDivReservationStations[i].Qk = ""; 911 | this->multDivReservationStations[i].Vj = ""; 912 | this->multDivReservationStations[i].Vk = ""; 913 | this->multDivReservationStations[i].instruction = nullptr; 914 | 915 | char numChar[10]; 916 | _itoa_s(num, numChar, 10); 917 | string val = "V"; 918 | val.append(numChar); 919 | 920 | broadCastResult(val, this->multDivReservationStations[i].name); 921 | num++; 922 | } 923 | 924 | 925 | } 926 | 927 | 928 | void execute() 929 | { 930 | for (int i = 0; i < totalLoadBuffers; i++) 931 | { 932 | if (this->loadBuffers[i].isBusy == false) 933 | continue; 934 | 935 | if (this->loadBuffers[i].fu != "") 936 | continue;//exeuction not started due to RAW hazard 937 | 938 | if (this->loadBuffers[i].instruction->instructionStatus.executionStart == -1) 939 | { 940 | if (this->loadBuffers[i].instruction->instructionStatus.issue == currentCycleNumber) 941 | continue; //the instruction has been issued in the current cycle, so it cannot being instruction in the current cycle. 942 | 943 | //execution started 944 | this->loadBuffers[i].instruction->instructionStatus.executionStart = currentCycleNumber; 945 | this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining--; 946 | 947 | 948 | if (this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining == 0) 949 | { //execution completed 950 | this->loadBuffers[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 951 | reason += "-> The instruction at Load Buffer= " + this->loadBuffers[i].name + " has completed execution.\n"; 952 | continue; 953 | } 954 | else 955 | { 956 | reason += "-> The instruction at Load Buffer= " + this->loadBuffers[i].name + " has started execution.\n"; 957 | continue; 958 | } 959 | } 960 | 961 | if (this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining!=0) 962 | this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining--; 963 | else continue; 964 | 965 | if (this->loadBuffers[i].instruction->instructionStatus.executionCyclesRemaining == 0) 966 | { //execution completed 967 | this->loadBuffers[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 968 | reason += "-> The instruction at Load Buffer= " + this->loadBuffers[i].name + " has completed execution.\n"; 969 | continue; 970 | } 971 | else 972 | { 973 | reason += "-> the instruction at Load Buffer= " + this->loadBuffers[i].name + " has completed one more execution cycle.\n"; 974 | continue; 975 | } 976 | 977 | 978 | }//end of load buffers loop 979 | 980 | 981 | for (int i = 0; i < totalStoreBuffers; i++) 982 | { 983 | if (this->storeBuffers[i].isBusy == false) 984 | continue; 985 | 986 | if (this->storeBuffers[i].fu != "") 987 | continue;//exeuction not started due to RAW hazard 988 | 989 | if (this->storeBuffers[i].instruction->instructionStatus.executionStart == -1) 990 | { 991 | if (this->storeBuffers[i].instruction->instructionStatus.issue == currentCycleNumber) 992 | continue; //the instruction has been issued in the current cycle, so it cannot start execution in the current cycle 993 | 994 | //execution started 995 | this->storeBuffers[i].instruction->instructionStatus.executionStart = currentCycleNumber; 996 | this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining--; 997 | 998 | if (this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining == 0) 999 | { //execution completed 1000 | this->storeBuffers[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1001 | reason += "-> The instruction at Store Buffer= " + this->storeBuffers[i].name + " has completed execution.\n"; 1002 | continue; 1003 | } 1004 | else 1005 | { 1006 | reason += "-> The instruction at Store Buffer= " + this->storeBuffers[i].name + " has started execution.\n"; 1007 | continue; 1008 | } 1009 | } 1010 | 1011 | if (this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining!=0) 1012 | this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining--; 1013 | else continue; 1014 | 1015 | if (this->storeBuffers[i].instruction->instructionStatus.executionCyclesRemaining == 0) 1016 | { //execution completed 1017 | this->storeBuffers[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1018 | reason += "-> The instruction at Store Buffer= " + this->storeBuffers[i].name + " has completed execution.\n"; 1019 | continue; 1020 | } 1021 | else 1022 | { 1023 | reason += "-> the instruction at Store Buffer= " + this->storeBuffers[i].name + " has completed one more execution cycle.\n"; 1024 | continue; 1025 | } 1026 | 1027 | }//end of store buffers loop 1028 | 1029 | 1030 | for (int i = 0; i < totalAddSubReservationStations; i++) 1031 | { 1032 | if (this->addSubReservationStations[i].isBusy == false) 1033 | continue; 1034 | 1035 | if (this->addSubReservationStations[i].Qj!="" || this->addSubReservationStations[i].Qk!="") 1036 | continue;//exeuction not started due to RAW hazard 1037 | 1038 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionStart == -1) 1039 | { 1040 | if (this->addSubReservationStations[i].instruction->instructionStatus.issue == currentCycleNumber) 1041 | continue; //the instruction has been issued in the current cycle, so it cannot start execution in the current cycle 1042 | 1043 | //execution started 1044 | this->addSubReservationStations[i].instruction->instructionStatus.executionStart = currentCycleNumber; 1045 | this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining--; 1046 | 1047 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining == 0) 1048 | { //execution completed 1049 | this->addSubReservationStations[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1050 | reason += "-> The instruction at Reservation Station= " + this->addSubReservationStations[i].name + " has completed execution.\n"; 1051 | continue; 1052 | } 1053 | else 1054 | { 1055 | reason += "-> The instruction at Reservation Station= " + this->addSubReservationStations[i].name + " has started execution.\n"; 1056 | continue; 1057 | } 1058 | } 1059 | 1060 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining!=0) 1061 | this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining--; 1062 | else continue; 1063 | 1064 | if (this->addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining == 0) 1065 | { //execution completed 1066 | this->addSubReservationStations[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1067 | reason += "-> The instruction at Reservation Station= " + this->addSubReservationStations[i].name + " has completed execution.\n"; 1068 | continue; 1069 | } 1070 | else 1071 | { 1072 | reason += "-> the instruction at Reservation Station= " + this->addSubReservationStations[i].name + " has completed one more execution cycle.\n"; 1073 | continue; 1074 | } 1075 | 1076 | }//end of addSub Reservation Stations loop 1077 | 1078 | 1079 | 1080 | //////////////////////////////////////////////////////////////////////// 1081 | for (int i = 0; i < totalMultDivReservationStations; i++) 1082 | { 1083 | if (this->multDivReservationStations[i].isBusy == false) 1084 | continue; 1085 | 1086 | if (this->multDivReservationStations[i].Qj != "" || this->multDivReservationStations[i].Qk != "") 1087 | continue;//exeuction not started due to RAW hazard 1088 | 1089 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionStart == -1) 1090 | { 1091 | if (this->multDivReservationStations[i].instruction->instructionStatus.issue == currentCycleNumber) 1092 | continue; //the instruction has been issued in the current cycle, so it cannot start execution in the current cycle 1093 | 1094 | //execution started 1095 | this->multDivReservationStations[i].instruction->instructionStatus.executionStart = currentCycleNumber; 1096 | this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining--; 1097 | 1098 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining == 0) 1099 | { //execution completed 1100 | this->multDivReservationStations[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1101 | reason += "-> The instruction at Reservation Station= " + this->multDivReservationStations[i].name + " has completed execution.\n"; 1102 | continue; 1103 | } 1104 | else 1105 | { 1106 | reason += "-> The instruction at Reservation Station= " + this->multDivReservationStations[i].name + " has started execution.\n"; 1107 | continue; 1108 | } 1109 | } 1110 | 1111 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining!=0) 1112 | this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining--; 1113 | else continue; 1114 | 1115 | if (this->multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining == 0) 1116 | { //execution completed 1117 | this->multDivReservationStations[i].instruction->instructionStatus.executionComplete = currentCycleNumber; 1118 | reason += "-> The instruction at Reservation Station= " + this->multDivReservationStations[i].name + " has completed execution.\n"; 1119 | continue; 1120 | } 1121 | else 1122 | { 1123 | reason += "-> the instruction at Reservation Station= " + this->multDivReservationStations[i].name + " has completed one more execution cycle.\n"; 1124 | continue; 1125 | } 1126 | 1127 | }//end of multDiv Reservation Stations loop 1128 | 1129 | 1130 | } 1131 | 1132 | void Simulate() 1133 | { 1134 | 1135 | int currentInstructionNumberToBeIssued = 0; 1136 | currentCycleNumber = 0; 1137 | 1138 | 1139 | 1140 | while (true) 1141 | { 1142 | gotoxy(0, 0); 1143 | cout << "Current Cycle Number= " << currentCycleNumber; 1144 | print(); 1145 | char a; 1146 | cin >> a; 1147 | currentCycleNumber++; 1148 | system("cls"); 1149 | reason = ""; 1150 | 1151 | int flag=issueInstruction(currentInstructionNumberToBeIssued); 1152 | 1153 | if (flag != -1) 1154 | currentInstructionNumberToBeIssued++; 1155 | 1156 | execute(); 1157 | writeBack(); 1158 | 1159 | 1160 | 1161 | } 1162 | 1163 | } 1164 | 1165 | void print() 1166 | { 1167 | int y = 2; 1168 | gotoxy(2, y); 1169 | cout << "Instructions:"; 1170 | gotoxy(27, y); 1171 | cout << " Issue" << " Start" << " Finish Write"; 1172 | gotoxy(27, y + 1); 1173 | 1174 | cout << "__________________________________"; 1175 | 1176 | int j = 0; 1177 | for (int i = 0; i < totalInstructions; i++) 1178 | { 1179 | char arr[10]; 1180 | _itoa_s(i, arr, 10); 1181 | strcat_s(arr, "."); 1182 | 1183 | gotoxy(2, j + y + 2); 1184 | if (instructions[i].instructionType == InstructionType::LOAD || instructions[i].instructionType == InstructionType::STORE) 1185 | cout <instructions[i].instructionStatus.issue, instructionIssue, 10); 1206 | _itoa_s(this->instructions[i].instructionStatus.executionStart, executionStart, 10); 1207 | _itoa_s(this->instructions[i].instructionStatus.executionComplete, executionComplete, 10); 1208 | _itoa_s(this->instructions[i].instructionStatus.writeBack, instructionWrite, 10); 1209 | 1210 | cout << "|" << std::right << setw(7) << (instructions[i].instructionStatus.issue==-1 ? "" : instructionIssue) << "|" << setw(7) << (instructions[i].instructionStatus.executionStart==-1 ? "" : executionStart) << "|" << setw(7) << (instructions[i].instructionStatus.executionComplete==-1 ? "" :executionComplete) << "|" << setw(10) << (instructions[i].instructionStatus.writeBack==-1 ? "" : instructionWrite) << "|"; 1211 | 1212 | gotoxy(2 + 24, j + y + 2); 1213 | 1214 | cout << "|_______|_______|_______|__________|"; 1215 | j++; 1216 | } 1217 | 1218 | //printing Load Store Buffer 1219 | gotoxy(70, y); 1220 | cout << "Load/Store Buffer: Busy Addr FU"; 1221 | y++; 1222 | gotoxy(66 + 22 + 2, y); 1223 | cout << "_____________________________"; 1224 | for (int i = 0; i < totalLoadBuffers; i++) 1225 | { 1226 | y++;; 1227 | gotoxy(76 + 2, y); 1228 | cout << setw(10) << std::right << loadBuffers[i].name; 1229 | cout << " "; 1230 | cout << "|" << std::right << setw(7) << (loadBuffers[i].isBusy == true ? "yes" : "no") << "|" << setw(10) << loadBuffers[i].address << "|" << setw(10) << loadBuffers[i].fu << "|"; 1231 | 1232 | if (loadBuffers[i].instruction != nullptr) 1233 | cout <instructionStatus.executionCyclesRemaining; 1234 | y++; 1235 | gotoxy(76 + 2 + 11, y); 1236 | cout << "|_______|__________|__________|" << endl; 1237 | } 1238 | 1239 | for (int i = 0; i < totalStoreBuffers; i++) 1240 | { 1241 | y++;; 1242 | gotoxy(76 + 2, y); 1243 | cout << setw(10)<instructionStatus.executionCyclesRemaining; 1248 | 1249 | y++; 1250 | gotoxy(76 + 2 + 11, y); 1251 | cout << "|_______|__________|__________|" << endl; 1252 | } 1253 | 1254 | 1255 | //reservation stations 1256 | y = (y > j ? y : j); 1257 | y += 5; 1258 | gotoxy(4, y); 1259 | cout << "Reservation Stations:"; 1260 | y++; 1261 | gotoxy(21, y); 1262 | cout << " Name Busy Op Vj Vk Qj Qk "; 1263 | 1264 | y++; 1265 | gotoxy(21 + 7, y); 1266 | cout << "_________________________________________________"; 1267 | for (int i = 0; i < totalAddSubReservationStations; i++) 1268 | { 1269 | y++; 1270 | gotoxy(19, y); 1271 | cout << std::right << setw(7) << addSubReservationStations[i].name << " |" << setw(5) << (addSubReservationStations[i].isBusy == true ? "yes" : "no") << "|" << setw(7) << addSubReservationStations[i].instructionType << "|" << setw(8) << addSubReservationStations[i].Vj << "|" << setw(8) << addSubReservationStations[i].Vk << "|" << setw(8) << addSubReservationStations[i].Qj << "|" << setw(8) << addSubReservationStations[i].Qk << "|"; 1272 | if (addSubReservationStations[i].instruction != nullptr) 1273 | { 1274 | cout << setw(3) << addSubReservationStations[i].instruction->instructionStatus.executionCyclesRemaining; 1275 | } 1276 | y++; 1277 | gotoxy(19 + 7 + 1, y); 1278 | cout << "|_____|_______|________|________|________|________|"; 1279 | } 1280 | 1281 | for (int i = 0; i < totalMultDivReservationStations; i++) 1282 | { 1283 | y++; 1284 | gotoxy(19, y); 1285 | cout << std::right << setw(7) << multDivReservationStations[i].name << " |" << setw(5) << (multDivReservationStations[i].isBusy == true ? "yes" : "no") << "|" << setw(7) << multDivReservationStations[i].instructionType << "|" << setw(8) << multDivReservationStations[i].Vj << "|" << setw(8) << multDivReservationStations[i].Vk << "|" << setw(8) << multDivReservationStations[i].Qj << "|" << setw(8) << multDivReservationStations[i].Qk << "|"; 1286 | 1287 | if (multDivReservationStations[i].instruction != nullptr) 1288 | { 1289 | cout << setw(3) << multDivReservationStations[i].instruction->instructionStatus.executionCyclesRemaining; 1290 | } 1291 | 1292 | y++; 1293 | gotoxy(19 + 7 + 1, y); 1294 | cout << "|_____|_______|________|________|________|________|"; 1295 | } 1296 | 1297 | y+=3; 1298 | int x = 19; 1299 | 1300 | 1301 | for (int i = 0; i < totalRegisters; i++) 1302 | { 1303 | gotoxy(x, y); 1304 | cout <