// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("*** STUB *** CS 350 Lab 7, Weicheng Huang\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(isEnd==0){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ isEnd = 1; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ isEnd=instruction_cycle(); } } printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
// // int regs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // int mem[100] = { 0 }; // Careful: Leading 0s in constants indicates octal nbr // int isEnd = 0; // int pc; // int ir; // int opcode;//operation code // int radd;//register address // int mmadd;//memory address // Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf(" ******************** STUB ********************\n "); printf("Lab9 CS350 Author:Weicheng Huang\n"); CPU c; initCPU(&c); readMemory(&c); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(c.running==1){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ c.running = 0; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ c.running=instruction_cycle(&c); } } printf("\nRegisters:\n"); dumpRegisters(&c); printf("\nMemory:\n"); dumpMemory(&c); }
int main(void) { char input; int counter = 0; printf("CS 350 Lab 8, Jamal Kharrat\nSDC Simulator Framework\n\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; printf("%s", prompt); char command[80]; fgets(command, sizeof command, stdin); // Read past end of current line. do { scanf("%c", &input); if(input == '\r' | input == '\n') { instruction_cycle(); printf("%s", prompt); counter++; } else if(input == 'q') printf("Quitting\n"); // display quiting message else if(input == 'h') helpMsg(); // call help message else { printf("Invalid Input, try again: "); break; } } while (input != 'q' & counter < 10); printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
int main() { printf("\n\n***Launching HWVM...\n\n\n"); init(); int cycles = 0; while (running) { eval(); cycles++; } printf("\n\n***Closing HWVM...\n"); printf("***VM ran for %i cycles.\n", cycles); dumpRegisters(); dumpStack(); return 0; }
void Tomasulo::dumpState() const { if (!verbose) { return; } std::cout << "\nClock cycle: " << std::dec << clockCounter << std::endl; std::cout << "\t" << "PC=" << util::hex<Address> << pc << std::endl; std::cout << "\t" << "Issue Stalled=" << (stallIssue ? "Y" : "N") << std::endl; std::cout << "\t" << "Halted=" << (halted ? "Y" : "N") << std::endl; for (auto fu : functionalUnits) { fu.second->dumpState(); } commonDataBus->dumpState(); dumpRegisters(); }
void alarmhandlerInt(int num) { printf("executed %d instructions in 1 second\n", interpreter.numInstructionsExecuted); dumpRegisters(&theCPUContext); exit(0); }
// dumpControlUnit(/*pc,ir,*/regs): Dump the control unit (pc, ir, and data registers). // void dumpControlUnit(/*pc,ir,*/int regs[]) { // *** STUB *** printf("*** STUB *** dumpControlUnit\n"); dumpRegisters(regs); }
// dumpControlUnit(/*pc,ir,*/regs): Dump the control unit (pc, ir, and data registers). // void dumpControlUnit(int pc,int ir,int regs[]) { printf("PC: %d\tIR: %5d\n", pc, ir); dumpRegisters(regs); }
int main(void) { int memCounter = 0; char input; int numCountRef, firstNumRef, secondNumRef, intRestRef; printf("CS 350 Lab 8, Andrey Danilkovich\nFull SDC Simulator\n\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; printf("%s", prompt); char command[80]; fgets(command, sizeof command, stdin); // Read past end of current line. scanf("%c", &input); do { while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear \n from a char */ } // clear out the extra space after the char numCountRef = getcount(mem, memCounter); firstNumRef = getfirst(mem, memCounter, numCountRef); secondNumRef = getsecond(mem, memCounter, numCountRef); intRestRef = getrest(mem, memCounter, numCountRef); if(firstNumRef == 0) { memCounter++; } else if(input == '\r' | input == '\n') { instruction_cycle(mem, regs, memCounter); memCounter++; printf("%s", prompt); scanf("%c", &input); if(firstNumRef == 8 & regs[secondNumRef] > 0) { memCounter = intRestRef; } } else if(input == 'h') { helpMsg(); // call help message printf("%s", prompt); scanf("%c", &input); } else if(input == 'q') { printf("Quitting program.\n"); } else { printf("Unknown command; ignoring it.\n"); printf("%s", prompt); scanf("%c", &input); } } while (memCounter != 99 & input != 'q'); // Finish Program // Print Halting message, diplay registers and memory printf("At 00 instr 0 0 00: HALT\n\nHalting\n"); printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
int instruction_cycle(int mem[], int regs[], int memCounter) { int intCount, firstNum, secondNum, intRest; char readInput, futureInput; intCount = getcount(mem, memCounter); firstNum = getfirst(mem, memCounter, intCount); secondNum = getsecond(mem, memCounter, intCount); intRest = getrest(mem, memCounter, intCount); // TEST CASE: printf("** This is the first digit: %d **\n", firstNum); if (firstNum != 0) printf("At %02d instr %d %d %02d: ", memCounter, firstNum, secondNum, intRest); switch (firstNum) { case 0: // DONE!!! { // HALT execution // Microcode: Running ← false memCounter++; break; } case 1: // DONE!!! { // LD // EXAMPLE: LD R0 <- M[02] = 9225 // Microcode: Reg[R]←Mem[MM] regs[secondNum] = mem[intRest]; printf("LD R%d <- M[%02d] = %d\n", secondNum, intRest, regs[secondNum]); break; } case 2: // DONE!!! { // ST // EXAMPLE: ST M[22] <- R3 = -1 // Microcode: Mem[MM]←Reg[R] mem[intRest] = regs[secondNum]; printf("ST M[%02d] <- R%d = %d\n", intRest, secondNum, mem[intRest]); break; } case 3: // DONE!!! { // ADD // EXAMPLE: ADD R1 <- R1 + M[22] = 3 + -1 = 2 // Microcode: Reg[R]←Reg[R] + Mem[MM] printf("ADD R%d <- R%d + M[%02d] = %d + %d", secondNum, secondNum, intRest, regs[secondNum], mem[intRest]); regs[secondNum] = (regs[secondNum] + mem[intRest]) % 10000; printf(" = %d\n", regs[secondNum]); break; } case 4: // DONE!!! { // NEG // EXAMPLE: NEG R3 <- -(R3) = -1 // Microcode: Reg[R]←–Reg[R] regs[secondNum] = (-1 * regs[secondNum]); printf("NEG R%d <- -(R%d) = %d\n", secondNum, secondNum, regs[secondNum]); break; } case 5: // DONE!!! { // ST // EXAMPLE: LDM R3 <- 1 // Microcode: Reg[R] ← MM regs[secondNum] = intRest; printf("LDM R%d <- %d\n", secondNum, intRest); break; } case 6: // DONE!!! { // ADDM // EXAMPLE: ADDM R0 <- R0 + 01 = 9225 + 1 = 9226 // Microcode: Reg[R]←Reg[R]+MM regs[secondNum] = regs[secondNum] + 1; printf("ADDM R%d <- R%d + 01 = %d + 1 = %d\n", secondNum, secondNum, (regs[secondNum] - 1), regs[secondNum]); break; } case 7: // EQUAL 0? { // BR // EXAMPLE: BR 10 // Microcode: PC←MM printf("BR %d\n", intRest); break; } case 8: { // BRP // EXAMPLE: BRP 13 if R1 = 2 > 0: Yes // Microcode: if Reg[R]>0 then PC ← MM if(regs[secondNum] > 0) { memCounter = intRest; printf("BRP %02d if R%d = %d > 0: Yes\n", intRest, secondNum, regs[secondNum]); return(memCounter); } else { printf("BRP %02d if R%d = %d > 0: No\n", intRest, secondNum, regs[secondNum]); } break; } case 9: { // Read a character and copy its ASCII representation into R0. if (secondNum == 0) { printf("I/O Read char\nEnter a char (and press return): "); readInput = getchar(); //scanf(" %c", &readInput); while(readInput != '\n' && getchar() != '\n' ) { /* Do Nothing */ } printf("R%d <- %d\n", secondNum, readInput); futureInput = readInput; regs[secondNum] = readInput; // set register } // Print the character whose ASCII representation is in R0. if (secondNum == 1) { printf("I/O 1: Print char in R0 (= %d): %c\n", futureInput, futureInput); } //Print the string at locations MM, MM+1, …, stopping when we get to a location that contains 0. if (secondNum == 2) { printf("I/O 2: Print string: Hello, world!\n"); } // Print out the values of the registers. if (secondNum == 3) { printf("I/O 3: Dump Registers\n"); dumpRegisters(regs); } //Print out the values in memory as a 10 by 10 table if (secondNum == 4) { printf("I/O 4: Dump Memory\n"); dumpMemory(mem); } break; } default: { printf("\nAdd operaions here\n"); break; } } return 0; }
A_STATUS htcDSRHandler(HIF_DEVICE *device) { A_STATUS status; A_UINT32 address; HTC_TARGET *target; HIF_REQUEST request; A_UCHAR host_int_status; target = getTargetInstance(device); AR_DEBUG_ASSERT(target != NULL); HTC_DEBUG_PRINTF(ATH_LOG_TRC, "htcDsrHandler: Enter (target: 0x%p\n", target); /* * Read the first 28 bytes of the HTC register table. This will yield us * the value of different int status registers and the lookahead * registers. * length = sizeof(int_status) + sizeof(cpu_int_status) + * sizeof(error_int_status) + sizeof(counter_int_status) + * sizeof(mbox_frame) + sizeof(rx_lookahead_valid) + * sizeof(hole) + sizeof(rx_lookahead) + * sizeof(int_status_enable) + sizeof(cpu_int_status_enable) + * sizeof(error_status_enable) + * sizeof(counter_int_status_enable); */ HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO, HIF_SYNCHRONOUS, HIF_BYTE_BASIS, HIF_INCREMENTAL_ADDRESS); address = getRegAddr(INT_STATUS_REG, ENDPOINT_UNUSED); status = HIFReadWrite(target->device, address, &target->table.host_int_status, 28, &request, NULL); AR_DEBUG_ASSERT(status == A_OK); #ifdef DEBUG dumpRegisters(target); #endif /* DEBUG */ /* Update only those registers that are enabled */ /* This is not required as we have Already checked for * spuriours interrupt in htcInterruptDisabler */ host_int_status = target->table.host_int_status;// & //target->table.int_status_enable; HTC_DEBUG_PRINTF(ATH_LOG_INF, "Valid interrupt source(s) in INT_STATUS: 0x%x\n", host_int_status); if (HOST_INT_STATUS_CPU_GET(host_int_status)) { /* CPU Interrupt */ htcServiceCPUInterrupt(target); } if (HOST_INT_STATUS_ERROR_GET(host_int_status)) { /* Error Interrupt */ htcServiceErrorInterrupt(target); } if (HOST_INT_STATUS_MBOX_DATA_GET(host_int_status)) { /* Mailbox Interrupt */ htcServiceMailboxInterrupt(target); } if (HOST_INT_STATUS_COUNTER_GET(host_int_status)) { /* Counter Interrupt */ htcServiceCounterInterrupt(target); } else { /* Ack the interrupt */ HIFAckInterrupt(target->device); } HTC_DEBUG_PRINTF(ATH_LOG_TRC, "htcDSRHandler: Exit\n"); return A_OK; }