void testInstruction(){ printf("Initializing instruction table...\n"); initialize(); printf("Inserting nop instruction at address 0...\n"); insertInstruction(0, "nop", ""); printf("Using fetchOpcode at address 0...\n"); if(strcmp(fetchOpcode(0), "nop") != 0){ printf("Failure! The nop instruction was not fetched!\n"); } else{ printf("Success! The nop instruction was fetched!\n"); } printf("Inserting 'pop A' instruction at address 1...\n"); insertInstruction(1, "pop", "A"); printf("Fetching operand at address 1...\n"); if(strcmp(fetchOperand(1), "A") !=0){ printf("Failure! The operand 'A' was not fetched.\n"); } else{ printf("Success! The operand 'A' was fetched!\n"); } printf("Attempting to insert a nop at an invalid address...\n"); insertInstruction(-1, "nop", ""); printf("\nAll tests concluded.\n"); }
void readInstructions(FILE * fp) { int address = 0; char opcode[OPCODE_SIZE]; char operand[OPERAND_SIZE]; printf("\n** Output **\n\n"); while(fscanf(fp, "%s", opcode) != EOF){ // operand check(read into operand var) if(hasOperand(opcode)){ fscanf(fp, "%s", operand); } else{ operand[0] = 0; } // insert the instruction into the instruction table insertInstruction(address, opcode, operand); address++; // discard any possible comments on current line discardline(fp); } }
BrewDayScrollWidget::BrewDayScrollWidget(QWidget* parent) : QWidget(parent), doc(new QWebView()) { setupUi(this); setObjectName("BrewDayScrollWidget"); recObs = 0; connect( listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showInstruction(int)) ); // connect( plainTextEdit, SIGNAL(textChanged()), this, SLOT(saveInstruction()) ); connect(btTextEdit,SIGNAL(textModified()), this, SLOT(saveInstruction())); connect( pushButton_insert, SIGNAL(clicked()), this, SLOT(insertInstruction()) ); connect( pushButton_remove, SIGNAL(clicked()), this, SLOT(removeSelectedInstruction()) ); connect( pushButton_up, SIGNAL(clicked()), this, SLOT(pushInstructionUp()) ); connect( pushButton_down, SIGNAL(clicked()), this, SLOT(pushInstructionDown()) ); connect( pushButton_generateInstructions, SIGNAL(clicked()), this, SLOT(generateInstructions()) ); }
insn_iterator insert(Opcode op, immediate_t&& immed, unsigned line) { return insertInstruction(boost::none_t(), op, &immed, line); }
insn_iterator insert(boost::optional<Label> l, Opcode op, immediate_t&& immed, unsigned line) { return insertInstruction(l, op, &immed, line); }
insn_iterator insert(Opcode op, unsigned line) { return insertInstruction(boost::none_t(), op, nullptr, line); }
insn_iterator insert(boost::optional<Label> l, Opcode op, unsigned line) { return insertInstruction(l, op, nullptr, line); }
void main(int argc, char *argv[]){ char *filename = argv[1]; FILE *fp; if(strcmp(filename, "-s") == 0){ testStack(); exit(0); } if(strcmp(filename, "-t") == 0){ testTable(); exit(0); } if(strcmp(filename, "-i") == 0){ testInstruction(); exit(0); } if(argc == 1){ printf("Proper use: wi <filename.wic>\n"); exit(0); } else if((fp = fopen(filename, "r")) == NULL) { printf("Error opening file. File doesn't exist.\n"); exit(0); } initialize(); char opcode[OPCODE_SIZE]; char operand[OPERAND_SIZE]; int address = 0; while(fscanf(fp, "%s", opcode) != EOF){ if(hasOperand(opcode)){ if(fscanf(fp, "%s", operand) == EOF){ insertInstruction(address, opcode, operand); address++; break; } } if(!validOp(opcode)){ if(fscanf(fp, "%s", operand) != EOF && strcmp(operand, "label") == 0){ char temp[OPERAND_SIZE]; strcpy(temp, operand); strcpy(operand, opcode); strcpy(opcode, temp); } else{ printf("Invalid opcode: %s\n", opcode); exit(0); } } else if(hasOperand(opcode) == 0){ strcpy(operand, ""); } insertInstruction(address, opcode, operand); address++; //discard the rest of the line while(fgetc(fp) != '\n'){}; } fclose(fp); runProgram(); }