我試圖將程序集轉換爲機器代碼。我有一個MINGW編譯器,如果我輸入./convert.exe mov%a,那麼它應該輸出0x01 0xc0。我正在考慮使用一個結構列出每個彙編代碼及其相應的機器值。此刻,我不斷收到類似於「請求會員操作碼而不是結構」的錯誤。任何幫助,將不勝感激。將單個程序集轉換爲機器代碼
#include <stdio.h>
#include <string.h>
struct _Instruction {
char mnemonic[10];
unsigned char opcode;} typedef Instruction;
Instruction instruction_list[] = {
{"mov", 0x01},
{"add", 0x04},
{"sub", 0x05},
{"mul",0x06},
{"div", 0x07},
{"and",0x08},
{"or",0x09},
{"xor",0x0a},
{"cmp",0x0b},
{"",-1},
};
Instruction get_inst(char mnemonic[]);
int main2(int argc, char *argv[])
{
char* instruction = argv[1];
Instruction get_inst = get_Instruction(instruction);
printf("%s ; %s",instruction_list.mnemonic,instruction_list.opcode);
return 0;
}
Instruction get_inst(char mnemonic[])
{
int i;
for(i=0; instruction_list[i].opcode != -1; i++)
{
if(!strcmp(instruction_list[i].mnemonic, mnemonic))
{
return instruction_list[i];
}
}
return instruction_list[i];
}
從閱讀[問]開始。然後正確格式化這個混亂。在類型說明符之後加入'typedef'已被棄用。 – Olaf
'instruction_list.opcode'應該是'get_inst.opcode'不應該嗎? 'instruction_list.mnemonic'也一樣。 – immibis
'struct _Instruction {...} typedef指令;' - >'typedef struct _Instruction {...}指令;' –