I'm trying to pass a char array to this function then print whatever it assigned mnemonic (last argument) to be, so something like
char mnemonic[3];
what_op(char array, char x, mnemonic)
printf("%s\n", mnemonic); //this works when place immediately after e.g. mnemonic = "MOV";
This doesn't seem to work - a serious pointer mess occurs, all sorts of things get printed out but not the mnemonic. This might not even be a sensible task in C but if there is an easy fix please let me know!
Thanks in advance for any help.
Function:
int what_op(char opcode[], char op_char_6, char mnemonic[])
{
if (opcode[0] == '0' && opcode[1] == '0')
{
if (opcode[3] == '1' && opcode[4] == '1' && opcode[5] == '0' &&
opcode[6] == '1')
{
mnemonic = "MOV";
printf("BUMS: %s\n", mnemonic);
return 1;
}
else if (opcode[3] == '0' && opcode[4] == '1' && opcode[5] == '0' &&
opcode[6] == '0')
{
mnemonic = "ADD";
return 2;
}
else if (opcode[3] == '0' && opcode[4] == '0' && opcode[5] == '1' &&
opcode[6] == '0')
{
mnemonic = "SUB";
return 3;
}
else if (opcode[3] == '1' && opcode[4] == '0' && opcode[5] == '1' &&
opcode[6] == '0')
{
mnemonic = "CMP";
return 4;
}
else if (opcode[3] == '0' && opcode[4] == '0' && opcode[5] == '0' &&
opcode[6] == '0')
{
if (opcode[0] == '0' && opcode[1] == '0' && opcode[2] == '0' && op_char_6 == '9')
{
mnemonic = "MUL";
return 14;
}
mnemonic = "AND";
return 5;
}
else if (opcode[3] == '0' && opcode[4] == '0' && opcode[5] == '0' &&
opcode[6] == '1')
{
if (opcode[0] == '0' && opcode[1] == '0' && opcode[2] == '0' && op_char_6 == '9')
{
mnemonic = "MLA";
return 15;
}
mnemonic = "EOR";
return 6;
}
else if (opcode[3] == '1' && opcode[4] == '1' && opcode[5] == '0' &&
opcode[6] == '0')
{
mnemonic = "ORR";
return 7;
}
else if (opcode[3] == '1' && opcode[4] == '1' && opcode[5] == '1' &&
opcode[6] == '0')
{
mnemonic = "BIC";
return 8;
}
else return 0;
}
else
{
if (opcode[0] == '1' && opcode[1] == '0' && opcode[2] == '1' && opcode[3] == '0')
{
mnemonic = "B";
return 9;
}
else if (opcode[0] == '1' && opcode[1] == '0' && opcode[2] == '1' && opcode[3] == '1')
{
mnemonic = "BL";
return 10;
}
else if (opcode[0] == '0' && opcode[1] == '1' && opcode[7] == '1')
{
mnemonic = "LDR";
return 11;
}
else if (opcode[0] == '0' && opcode[1] == '1' && opcode[7] == '0')
{
mnemonic = "STR";
return 12;
}
else if (opcode[0] == '1' && opcode[1] == '1' && opcode[2] == '1' && opcode[3] == '1')
{
mnemonic = "SVC";
return 13;
}
else return 0;
}
}

New Topic/Question
Reply




MultiQuote




|