I am building a meta assembler and am currently trying to get the input. The input consists of *OPCODE**SPACE**Max of 3 character Hex OPERAND*
.
This is the code that I have so far:
string input;
while(input != "DONE"){
if(input == "DONE"){
break;
}
cout<<"Enter the opcode/operand to enter an instruction or 'DONE' to exit: ";
cin>>input;
// Seperate input
bool opcode_bool = true;
string opcode;
string operand;
for(int i = 0; i < input.length(); i++){
if(input[i] == ' '){
opcode_bool = false;
continue;
}
if(opcode_bool == true){
opcode = opcode + input[i];
}else{
operand = operand + input[i];
}
}
cout<<opcode<<endl<<operand<<endl;
cout<<"END OF ITERATION"<<endl;
}
When I enter a combination of letters and numbers eg ADDI AB3
, the following happens when the loop tries to separate the two parts into the opcode and operand.
For some reason the input gets split up and run as two iterations of the while loop instead of as one, so that the for loop can split it up into two parts.
Help is appreciated!