Last active
August 3, 2025 21:15
-
-
Save tweetandcode/8aa6e9ce3eee0b19fd9ab0ba3c0085a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdint.h> | |
| char segoverride[4] = ""; | |
| char buffer[100]; | |
| #define parse_mod_reg_rnm \ | |
| fread(&b, 1, 1, f); \ | |
| int mod = (b >> 6) & 0x03; \ | |
| int reg = (b >> 3) & 0x07; \ | |
| int rnm = b & 0x07 | |
| #define parse_imm_wide_to \ | |
| int imm = b & 0x7; \ | |
| int wide = b & 0x01;\ | |
| int to = (b >> 1) & 0x01 | |
| #define parse_data8 int data;\ | |
| fread(&data, 1, 1, f) | |
| #define parse_data16 int data;\ | |
| u8 hi, lo;\ | |
| fread(&lo, 1, 1, f);\ | |
| fread(&hi, 1, 1, f);\ | |
| data = (hi<<8) | lo | |
| typedef uint8_t u8; | |
| typedef void (* out_fn)(FILE *f, u8 b); | |
| out_fn ops_table[256]; | |
| char *regs16[8] = {"ax", "cx", "dx", "bx", "sp","bp","si","di"}; | |
| char *regs8[8] = {"al","cl","dl","bl","ah","ch","dh","bh"}; | |
| char **regs[2] = { regs8, regs16 }; | |
| char *rnm0[8] = {"bx + si","bx + di","bp + si","bp + di","si","di","bp","bx"}; | |
| void not_implemented(FILE *f, u8 b) { printf("op[%hhx] not implemented\n", b); } | |
| void not_used(FILE *f, u8 b) { printf("op[%hhx] not used\n", b); } | |
| char *get_mem_str(FILE *f, int mod, int rnm) { | |
| if(mod == 0) { | |
| if(rnm == 6) { | |
| int displacement; | |
| u8 dhi, dlo; | |
| fread(&dlo, 1, 1, f); | |
| fread(&dhi, 1, 1, f); | |
| displacement = (dhi << 8) | dlo; | |
| sprintf(buffer, "%s[%d]", segoverride, displacement); | |
| } else { | |
| sprintf(buffer, "%s[%s]", segoverride, rnm0[rnm]); | |
| } | |
| } else if(mod == 1) { | |
| int displacement; | |
| u8 dlo; | |
| fread(&dlo, 1, 1, f); | |
| displacement = dlo; | |
| sprintf(buffer, "%s[%s%+d]", segoverride, rnm0[rnm], (int8_t)displacement); | |
| } else if(mod == 2) { | |
| int displacement; | |
| u8 dhi, dlo; | |
| fread(&dlo, 1, 1, f); | |
| fread(&dhi, 1, 1, f); | |
| displacement = (dhi << 8) | dlo; | |
| sprintf(buffer, "%s[%s%+d]", segoverride, rnm0[rnm], (int16_t)displacement); | |
| } | |
| return buffer; | |
| } | |
| void mov_immediate_to_register(FILE *f, u8 b) | |
| { | |
| int wide = (b >> 3) & 0x1; | |
| int reg = b & 0x7; | |
| char lo, hi; | |
| int data; | |
| fread(&lo, 1, 1, f); | |
| data = lo; | |
| if(wide) | |
| { | |
| fread(&hi, 1, 1, f); | |
| data = ((hi & 0xff) << 8) | (lo & 0xff); | |
| } | |
| printf("mov %s, %hd\n", regs[wide][reg], data); | |
| } | |
| void print_inst(char *inst, char *lhs, char *rhs, int to) { | |
| if(to) printf("%s %s, %s\n", inst, lhs, rhs); | |
| else printf("%s %s, %s\n", inst, rhs, lhs); | |
| } | |
| void mov_memory_to_acc(FILE *f, u8 b) | |
| { | |
| parse_data16; | |
| printf("mov ax, [%d]\n", data); | |
| } | |
| void mov_acc_to_memory(FILE *f, u8 b) | |
| { | |
| parse_data16; | |
| printf("mov [%d], ax\n", data); | |
| } | |
| void mov_immed_to_mem(FILE *f, u8 b) { | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| if(wide) { | |
| get_mem_str(f, mod, rnm); | |
| parse_data16; | |
| printf("mov %s, word %d\n", buffer, (uint16_t)data); | |
| } else { | |
| get_mem_str(f, mod, rnm); | |
| parse_data8; | |
| printf("mov %s, byte %d\n", buffer, (u8)data); | |
| } | |
| } | |
| void mov_rom_to_rom(FILE *f, u8 b) { | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| if(mod == 3) { | |
| print_inst("mov", regs[wide][reg], regs[wide][rnm], to); | |
| } else { | |
| print_inst("mov", regs[wide][reg], get_mem_str(f, mod, rnm), to); | |
| } | |
| } | |
| void add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom(FILE *f, u8 b) { | |
| int index = (b >> 3) & 0x7; | |
| char *inst[8] = {"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"}; | |
| parse_imm_wide_to; | |
| if(imm == 4) { | |
| parse_data8; | |
| printf("%s al, %d\n", inst[index], (int8_t)data); | |
| } else if(imm == 5) { | |
| parse_data16; | |
| printf("%s ax, %d\n", inst[index], data); | |
| } else { | |
| parse_mod_reg_rnm; | |
| if(mod == 3) print_inst(inst[index], regs[wide][reg], regs[wide][rnm], to); | |
| else print_inst(inst[index], regs[wide][reg], get_mem_str(f, mod, rnm), to); | |
| } | |
| } | |
| void add_or_adc_sbb_and_sub_xor_cmp_immed(FILE *f, u8 b) { | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| char *inst[8] = {"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"}; | |
| char dataBuffer[100]; | |
| if(mod == 3) { | |
| if(wide && to == 0) { | |
| parse_data16; | |
| sprintf(dataBuffer, "%d", (int16_t)data); | |
| } else { | |
| parse_data8; | |
| sprintf(dataBuffer, "%d", (int8_t)data); | |
| } | |
| print_inst(inst[reg], regs[wide][rnm], dataBuffer, 1); | |
| } else { | |
| get_mem_str(f, mod, rnm); | |
| if(wide && to == 0) { | |
| parse_data16; | |
| sprintf(dataBuffer, "%d", (int16_t)data); | |
| } else { | |
| parse_data8; | |
| sprintf(dataBuffer, "%d", (int8_t)data); | |
| } | |
| char sizeBuffer[100]; | |
| sprintf(sizeBuffer, "%s %s", wide ? "word":"byte", buffer); | |
| print_inst(inst[reg], sizeBuffer, dataBuffer, 1); | |
| } | |
| } | |
| void inc_dec_call_jmp_push(FILE *f, u8 b) { | |
| parse_mod_reg_rnm; | |
| char *inst[8] = {"inc", "dec", "call", "call", "jmp", "jmp", "push", "not usec"}; | |
| if(mod == 3) printf("%s %s\n", inst[reg], regs[1][rnm]); | |
| else printf("%s word %s\n", inst[reg], get_mem_str(f, mod, rnm)); | |
| } | |
| void push_cs(FILE *f, u8 b) { | |
| printf("push cs\n", b); | |
| } | |
| void pop_ds(FILE *f, u8 b) { | |
| printf("pop ds\n"); | |
| } | |
| void pop_rom16(FILE *f, u8 b) { | |
| parse_mod_reg_rnm; | |
| if(mod == 3) printf("pop %s\n", regs[1][rnm]); | |
| else printf("pop word %s\n", get_mem_str(f, mod, rnm)); | |
| } | |
| void xchg_acc_reg16(FILE *f, u8 b) { | |
| int reg = b & 0x7; | |
| printf("xchg ax, %s\n", regs[1][reg]); | |
| } | |
| void xchg_reg_rom(FILE *f, u8 b){ | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| if(mod == 3) print_inst("xchg", regs[wide][reg], regs[wide][rnm], 1); | |
| else print_inst("xchg", regs[wide][reg], get_mem_str(f, mod, rnm), 1); | |
| } | |
| void in_out_acc(FILE *f, u8 b) { | |
| int index = b & 0x3; | |
| int wide = b & 0x1; | |
| if(index < 2) printf("in %s, dx\n", wide ? "ax":"al"); | |
| else printf("out dx, %s\n", wide ? "ax":"al"); | |
| } | |
| void in_out_immed8(FILE *f, u8 b) { | |
| int index = b & 0x3; | |
| int wide = b & 0x1; | |
| parse_data8; | |
| if(index < 2) printf("in %s, %d\n", wide ? "ax":"al", (u8)data); | |
| else printf("out %d, %s\n", (u8)data, wide ? "ax":"al"); | |
| } | |
| void xlat(FILE *f, u8 b) { | |
| printf("xlat\n"); | |
| } | |
| void lea_lds_les_reg16_mem16(FILE *f, u8 b) { | |
| int index = ((b & 0x8) >> 2) | (b & 0x1); | |
| char *inst[4] = {"les", "lds", "not used", "lea"}; | |
| parse_mod_reg_rnm; | |
| print_inst(inst[index], regs[1][reg], get_mem_str(f, mod, rnm), 1); | |
| } | |
| void pushf_popf_sahf_lahf(FILE *f, u8 b) { | |
| int b2 = b&0x3; | |
| char *ppslf[4] = {"pushf", "popf", "sahf", "lahf"}; | |
| printf("%s\n", ppslf[b2]); | |
| } | |
| void inc_dec_reg16(FILE *f, u8 b) { | |
| int reg = b & 0x7; | |
| int dec = (b >> 3) & 0x1; | |
| printf("%s word %s\n", dec ? "dec": "inc", regs[1][reg]); | |
| } | |
| void push_pop_reg16(FILE *f, u8 b) { | |
| int reg = b & 0x7; | |
| int pop = (b >> 3) & 0x1; | |
| printf("%s %s\n", pop ? "pop": "push", regs[1][reg]); | |
| } | |
| void inc_dec_rom8(FILE *f, u8 b) { | |
| parse_mod_reg_rnm; | |
| char *inst[2] = {"inc", "dec"}; | |
| if(mod == 3) printf("%s %s\n", inst[reg], regs[0][rnm]); | |
| else printf("%s byte %s\n", inst[reg], get_mem_str(f, mod, rnm)); | |
| } | |
| void aaa(FILE *f, u8 b) { | |
| printf("aaa\n"); | |
| } | |
| void aas(FILE *f, u8 b) { | |
| printf("aas\n"); | |
| } | |
| void aam(FILE *f, u8 b) { | |
| fread(&b, 1, 1, f); | |
| printf("aam\n"); | |
| } | |
| void aad(FILE *f, u8 b) { | |
| fread(&b, 1, 1, f); | |
| printf("aad\n"); | |
| } | |
| void cbw(FILE *f, u8 b) { | |
| printf("cbw\n"); | |
| } | |
| void cwd(FILE *f, u8 b) { | |
| printf("cwd\n"); | |
| } | |
| void daa(FILE *f, u8 b) { | |
| printf("daa\n"); | |
| } | |
| void das(FILE *f, u8 b) { | |
| printf("das\n"); | |
| } | |
| void test_not_neg_mul_imul_div_idiv(FILE *f, u8 b) { | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| char *inst[8] = {"test", "not used", "not", "neg", "mul", "imul", "div", "idiv"}; | |
| char dataBuffer[100]; | |
| if(reg == 0) { | |
| if(mod == 3) { | |
| if(wide) { | |
| parse_data16; | |
| sprintf(dataBuffer, "%d", (int16_t) data); | |
| } else { | |
| parse_data8; | |
| sprintf(dataBuffer, "%d", (int8_t) data); | |
| } | |
| print_inst(inst[reg], regs[wide][rnm], dataBuffer, 1); | |
| } else { | |
| get_mem_str(f, mod, rnm); | |
| if(wide) { | |
| parse_data16; | |
| sprintf(dataBuffer, "%d", (int16_t) data); | |
| } else { | |
| parse_data8; | |
| sprintf(dataBuffer, "%d", (int8_t) data); | |
| } | |
| char sizeBuffer[100]; | |
| sprintf(sizeBuffer, "%s %s", wide ? "word":"byte", buffer); | |
| print_inst(inst[reg], sizeBuffer, dataBuffer, 1); | |
| } | |
| } else { | |
| if(mod == 3) { | |
| printf("%s %s\n", inst[reg], regs[wide][rnm]); | |
| } else { | |
| printf("%s %s %s\n", inst[reg], wide ? "word" : "byte", get_mem_str(f, mod, rnm)); | |
| } | |
| } | |
| } | |
| void rol_ror_rcl_rcr_shl_shr_sar(FILE *f, u8 b) { | |
| int si = (b >> 1) & 0x1; | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| char *inst[8] = {"rol", "ror", "rcl", "rcr", "shl", "shr", "not used", "sar"}; | |
| char *src[2] = {"1", "cl"}; | |
| if(mod == 3) print_inst(inst[reg], regs[wide][rnm], src[si], 1); | |
| else { | |
| char sizeBuffer[100]; | |
| sprintf(sizeBuffer, "%s %s", wide ? "word":"byte", get_mem_str(f, mod, rnm)); | |
| print_inst(inst[reg], sizeBuffer, src[si], 1); | |
| } | |
| } | |
| void test_rom_reg(FILE *f, u8 b){ | |
| parse_imm_wide_to; | |
| parse_mod_reg_rnm; | |
| if(mod == 3) print_inst("test", regs[wide][reg], regs[wide][rnm], 0); | |
| else { | |
| char sizeBuffer[100]; | |
| sprintf(sizeBuffer, "%s %s", wide ? "word":"byte", get_mem_str(f, mod, rnm)); | |
| print_inst("test", regs[wide][reg], sizeBuffer, 0); | |
| } | |
| } | |
| void test_ax_immed16(FILE *f, u8 b) { | |
| parse_data16; | |
| printf("test ax, %d\n", (int16_t) data); | |
| } | |
| void repne_rep_hlt_cmc(FILE *f, u8 b) { | |
| int index = b & 0x7; | |
| char *inst[8] = {"not used", "not used", "repne ", "rep ", "hlt\n", "cmc\n", "not used", "not used"}; | |
| printf("%s", inst[index]); | |
| } | |
| void movs_cmps_scas_lods_stos(FILE *f, u8 b) { | |
| char *inst[16] = { | |
| "0!", "1!", "2!", "3!", "movsb", | |
| "movsw", "cmpsb", "cmpsw", "8!", | |
| "9!", "stosb", "stosw", "lodsb", | |
| "lodsw", "scasb", "scasw" | |
| }; | |
| int index = b & 0xf; | |
| printf("%s\n", inst[index]); | |
| } | |
| void ret_immed8(FILE *f, u8 b) { | |
| parse_data16; | |
| printf("ret %d\n", (int16_t)data); | |
| } | |
| void ret(FILE *f, u8 b) { | |
| printf("ret\n"); | |
| } | |
| void all_jmps(FILE *f, u8 b) { | |
| int index = b & 0xf; | |
| char *inst[16] = { | |
| "jo", "jno", "jb", "jnb", "je", "jne", "jbe", "ja", | |
| "js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jg" | |
| }; | |
| parse_data8; | |
| printf("%s $+2%+d\n", inst[index], (int8_t)data); | |
| } | |
| void loops_jcxz(FILE *f, u8 b) { | |
| int index = b & 0x3; | |
| char *inst[4] = { "loopnz", "loopz", "loop", "jcxz" }; | |
| parse_data8; | |
| printf("%s $+2%+d\n", inst[index], (int8_t)data); | |
| } | |
| void interrupt3(FILE *f, u8 b) { | |
| printf("int 3\n"); | |
| } | |
| void interrupt(FILE *f, u8 b) { | |
| parse_data8; | |
| printf("int %d\n", (int8_t)data); | |
| } | |
| void into(FILE *f, u8 b) { | |
| printf("into\n"); | |
| } | |
| void iret(FILE *f, u8 b) { | |
| printf("iret\n"); | |
| } | |
| void clc_stc_cli_sti_std(FILE *f, u8 b) { | |
| int index = b & 0x7; | |
| char *inst[8] = {"clc", "stc", "cli", "sti", "cld", "std", "not used", "not used"}; | |
| printf("%s\n", inst[index]); | |
| } | |
| void wait(FILE *f, u8 b) { | |
| printf("wait\n"); | |
| } | |
| void lock(FILE *f, u8 b) { | |
| printf("lock "); | |
| } | |
| void seg_cs(FILE *f, u8 b) { | |
| segoverride[0] = 'c'; | |
| segoverride[1] = 's'; | |
| segoverride[2] = ':'; | |
| } | |
| void seg_ds(FILE *f, u8 b) { | |
| segoverride[0] = 'd'; | |
| segoverride[1] = 's'; | |
| segoverride[2] = ':'; | |
| } | |
| void seg_es(FILE *f, u8 b) { | |
| segoverride[0] = 'e'; | |
| segoverride[1] = 's'; | |
| segoverride[2] = ':'; | |
| } | |
| void seg_ss(FILE *f, u8 b) { | |
| segoverride[0] = 's'; | |
| segoverride[1] = 's'; | |
| segoverride[2] = ':'; | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| if(argc != 2) return printf("%s <binary_file>", argv[0]); | |
| // for(u8 i=0;i<255;i++) printf("ops_table[0x%hhx] = not_implemented;\n", i); | |
| // printf("ops_table[0x%hhx] = not_implemented;\n", 255); | |
| // return 0; | |
| // for(int i=0; i<256;i++) ops_table[i] = not_implemented; | |
| ops_table[0x00] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x01] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x02] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x03] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x04] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x05] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x06] = not_implemented; | |
| ops_table[0x07] = not_implemented; | |
| ops_table[0x08] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x09] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x0a] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x0b] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x0c] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x0d] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x0e] = push_cs; | |
| ops_table[0x0f] = not_implemented; | |
| ops_table[0x10] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x11] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x12] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x13] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x14] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x15] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x16] = not_implemented; | |
| ops_table[0x17] = not_implemented; | |
| ops_table[0x18] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x19] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x1a] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x1b] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x1c] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x1d] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x1e] = not_implemented; | |
| ops_table[0x1f] = pop_ds; | |
| ops_table[0x20] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x21] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x22] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x23] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x24] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x25] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x26] = seg_es; | |
| ops_table[0x27] = daa; | |
| ops_table[0x28] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x29] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x2a] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x2b] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x2c] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x2d] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x2e] = seg_cs; | |
| ops_table[0x2f] = das; | |
| ops_table[0x30] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x31] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x32] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x33] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x34] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x35] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x36] = seg_ss; | |
| ops_table[0x37] = aaa; | |
| ops_table[0x38] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x39] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x3a] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x3b] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x3c] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x3d] = add_or_adc_sbb_and_sub_xor_cmp_rom_to_rom; | |
| ops_table[0x3e] = seg_ds; | |
| ops_table[0x3f] = aas; | |
| ops_table[0x40] = inc_dec_reg16; | |
| ops_table[0x41] = inc_dec_reg16; | |
| ops_table[0x42] = inc_dec_reg16; | |
| ops_table[0x43] = inc_dec_reg16; | |
| ops_table[0x44] = inc_dec_reg16; | |
| ops_table[0x45] = inc_dec_reg16; | |
| ops_table[0x46] = inc_dec_reg16; | |
| ops_table[0x47] = inc_dec_reg16; | |
| ops_table[0x48] = inc_dec_reg16; | |
| ops_table[0x49] = inc_dec_reg16; | |
| ops_table[0x4a] = inc_dec_reg16; | |
| ops_table[0x4b] = inc_dec_reg16; | |
| ops_table[0x4c] = inc_dec_reg16; | |
| ops_table[0x4d] = inc_dec_reg16; | |
| ops_table[0x4e] = inc_dec_reg16; | |
| ops_table[0x4f] = inc_dec_reg16; | |
| ops_table[0x50] = push_pop_reg16; | |
| ops_table[0x51] = push_pop_reg16; | |
| ops_table[0x52] = push_pop_reg16; | |
| ops_table[0x53] = push_pop_reg16; | |
| ops_table[0x54] = push_pop_reg16; | |
| ops_table[0x55] = push_pop_reg16; | |
| ops_table[0x56] = push_pop_reg16; | |
| ops_table[0x57] = push_pop_reg16; | |
| ops_table[0x58] = push_pop_reg16; | |
| ops_table[0x59] = push_pop_reg16; | |
| ops_table[0x5a] = push_pop_reg16; | |
| ops_table[0x5b] = push_pop_reg16; | |
| ops_table[0x5c] = push_pop_reg16; | |
| ops_table[0x5d] = push_pop_reg16; | |
| ops_table[0x5e] = push_pop_reg16; | |
| ops_table[0x5f] = push_pop_reg16; | |
| ops_table[0x60] = not_used; | |
| ops_table[0x61] = not_used; | |
| ops_table[0x62] = not_used; | |
| ops_table[0x63] = not_used; | |
| ops_table[0x64] = not_used; | |
| ops_table[0x65] = not_used; | |
| ops_table[0x66] = not_used; | |
| ops_table[0x67] = not_used; | |
| ops_table[0x68] = not_used; | |
| ops_table[0x69] = not_used; | |
| ops_table[0x6a] = not_used; | |
| ops_table[0x6b] = not_used; | |
| ops_table[0x6c] = not_used; | |
| ops_table[0x6d] = not_used; | |
| ops_table[0x6e] = not_used; | |
| ops_table[0x6f] = not_used; | |
| ops_table[0x70] = all_jmps; //jo; | |
| ops_table[0x71] = all_jmps; | |
| ops_table[0x72] = all_jmps; | |
| ops_table[0x73] = all_jmps; | |
| ops_table[0x74] = all_jmps; | |
| ops_table[0x75] = all_jmps; | |
| ops_table[0x76] = all_jmps; | |
| ops_table[0x77] = all_jmps; | |
| ops_table[0x78] = all_jmps; | |
| ops_table[0x79] = all_jmps; | |
| ops_table[0x7a] = all_jmps; | |
| ops_table[0x7b] = all_jmps; | |
| ops_table[0x7c] = all_jmps; | |
| ops_table[0x7d] = all_jmps; | |
| ops_table[0x7e] = all_jmps; | |
| ops_table[0x7f] = all_jmps; | |
| ops_table[0x80] = add_or_adc_sbb_and_sub_xor_cmp_immed; | |
| ops_table[0x81] = add_or_adc_sbb_and_sub_xor_cmp_immed; | |
| ops_table[0x82] = add_or_adc_sbb_and_sub_xor_cmp_immed; | |
| ops_table[0x83] = add_or_adc_sbb_and_sub_xor_cmp_immed; | |
| ops_table[0x84] = test_rom_reg; | |
| ops_table[0x85] = test_rom_reg; | |
| ops_table[0x86] = xchg_reg_rom; | |
| ops_table[0x87] = xchg_reg_rom; | |
| ops_table[0x88] = mov_rom_to_rom; | |
| ops_table[0x89] = mov_rom_to_rom; | |
| ops_table[0x8a] = mov_rom_to_rom; | |
| ops_table[0x8b] = mov_rom_to_rom; | |
| ops_table[0x8c] = mov_rom_to_rom; | |
| ops_table[0x8d] = lea_lds_les_reg16_mem16; | |
| ops_table[0x8e] = not_implemented; | |
| ops_table[0x8f] = pop_rom16; | |
| ops_table[0x90] = xchg_acc_reg16; | |
| ops_table[0x91] = xchg_acc_reg16; | |
| ops_table[0x92] = xchg_acc_reg16; | |
| ops_table[0x93] = xchg_acc_reg16; | |
| ops_table[0x94] = xchg_acc_reg16; | |
| ops_table[0x95] = xchg_acc_reg16; | |
| ops_table[0x96] = xchg_acc_reg16; | |
| ops_table[0x97] = xchg_acc_reg16; | |
| ops_table[0x98] = cbw; | |
| ops_table[0x99] = cwd; | |
| ops_table[0x9a] = not_implemented; | |
| ops_table[0x9b] = wait; | |
| ops_table[0x9c] = pushf_popf_sahf_lahf; | |
| ops_table[0x9d] = pushf_popf_sahf_lahf; | |
| ops_table[0x9e] = pushf_popf_sahf_lahf; | |
| ops_table[0x9f] = pushf_popf_sahf_lahf; | |
| ops_table[0xa0] = mov_memory_to_acc; | |
| ops_table[0xa1] = mov_memory_to_acc; | |
| ops_table[0xa2] = mov_acc_to_memory; | |
| ops_table[0xa3] = mov_acc_to_memory; | |
| ops_table[0xa4] = movs_cmps_scas_lods_stos; | |
| ops_table[0xa5] = movs_cmps_scas_lods_stos; | |
| ops_table[0xa6] = movs_cmps_scas_lods_stos; | |
| ops_table[0xa7] = movs_cmps_scas_lods_stos; | |
| ops_table[0xa8] = not_implemented; | |
| ops_table[0xa9] = test_ax_immed16; | |
| ops_table[0xaa] = movs_cmps_scas_lods_stos; | |
| ops_table[0xab] = movs_cmps_scas_lods_stos; | |
| ops_table[0xac] = movs_cmps_scas_lods_stos; | |
| ops_table[0xad] = movs_cmps_scas_lods_stos; | |
| ops_table[0xae] = movs_cmps_scas_lods_stos; | |
| ops_table[0xaf] = movs_cmps_scas_lods_stos; | |
| ops_table[0xb0] = mov_immediate_to_register; | |
| ops_table[0xb1] = mov_immediate_to_register; | |
| ops_table[0xb2] = mov_immediate_to_register; | |
| ops_table[0xb3] = mov_immediate_to_register; | |
| ops_table[0xb4] = mov_immediate_to_register; | |
| ops_table[0xb5] = mov_immediate_to_register; | |
| ops_table[0xb6] = mov_immediate_to_register; | |
| ops_table[0xb7] = mov_immediate_to_register; | |
| ops_table[0xb8] = mov_immediate_to_register; | |
| ops_table[0xb9] = mov_immediate_to_register; | |
| ops_table[0xba] = mov_immediate_to_register; | |
| ops_table[0xbb] = mov_immediate_to_register; | |
| ops_table[0xbc] = mov_immediate_to_register; | |
| ops_table[0xbd] = mov_immediate_to_register; | |
| ops_table[0xbe] = mov_immediate_to_register; | |
| ops_table[0xbf] = mov_immediate_to_register; | |
| ops_table[0xc0] = not_used; | |
| ops_table[0xc1] = not_used; | |
| ops_table[0xc2] = ret_immed8; | |
| ops_table[0xc3] = ret; | |
| ops_table[0xc4] = lea_lds_les_reg16_mem16; | |
| ops_table[0xc5] = lea_lds_les_reg16_mem16; | |
| ops_table[0xc6] = mov_immed_to_mem; | |
| ops_table[0xc7] = mov_immed_to_mem; | |
| ops_table[0xc8] = not_used; | |
| ops_table[0xc9] = not_used; | |
| ops_table[0xca] = not_implemented; | |
| ops_table[0xcb] = not_implemented; | |
| ops_table[0xcc] = interrupt3; | |
| ops_table[0xcd] = interrupt; | |
| ops_table[0xce] = into; | |
| ops_table[0xcf] = iret; | |
| ops_table[0xd0] = rol_ror_rcl_rcr_shl_shr_sar; | |
| ops_table[0xd1] = rol_ror_rcl_rcr_shl_shr_sar; | |
| ops_table[0xd2] = rol_ror_rcl_rcr_shl_shr_sar; | |
| ops_table[0xd3] = rol_ror_rcl_rcr_shl_shr_sar; | |
| ops_table[0xd4] = aam; | |
| ops_table[0xd5] = aad; | |
| ops_table[0xd6] = not_used; | |
| ops_table[0xd7] = xlat; | |
| ops_table[0xd8] = not_implemented; | |
| ops_table[0xd9] = not_implemented; | |
| ops_table[0xda] = not_implemented; | |
| ops_table[0xdb] = not_implemented; | |
| ops_table[0xdc] = not_implemented; | |
| ops_table[0xdd] = not_implemented; | |
| ops_table[0xde] = not_implemented; | |
| ops_table[0xdf] = not_implemented; | |
| ops_table[0xe0] = loops_jcxz; | |
| ops_table[0xe1] = loops_jcxz; | |
| ops_table[0xe2] = loops_jcxz; | |
| ops_table[0xe3] = loops_jcxz; | |
| ops_table[0xe4] = in_out_immed8; | |
| ops_table[0xe5] = in_out_immed8; | |
| ops_table[0xe6] = in_out_immed8; | |
| ops_table[0xe7] = in_out_immed8; | |
| ops_table[0xe8] = not_implemented; | |
| ops_table[0xe9] = not_implemented; | |
| ops_table[0xea] = not_implemented; | |
| ops_table[0xeb] = not_implemented; | |
| ops_table[0xec] = in_out_acc; | |
| ops_table[0xed] = in_out_acc; | |
| ops_table[0xee] = in_out_acc; | |
| ops_table[0xef] = in_out_acc; | |
| ops_table[0xf0] = lock; | |
| ops_table[0xf1] = not_used; | |
| ops_table[0xf2] = repne_rep_hlt_cmc; | |
| ops_table[0xf3] = repne_rep_hlt_cmc; | |
| ops_table[0xf4] = repne_rep_hlt_cmc; | |
| ops_table[0xf5] = repne_rep_hlt_cmc; | |
| ops_table[0xf6] = test_not_neg_mul_imul_div_idiv; | |
| ops_table[0xf7] = test_not_neg_mul_imul_div_idiv; | |
| ops_table[0xf8] = clc_stc_cli_sti_std; | |
| ops_table[0xf9] = clc_stc_cli_sti_std; | |
| ops_table[0xfa] = clc_stc_cli_sti_std; | |
| ops_table[0xfb] = clc_stc_cli_sti_std; | |
| ops_table[0xfc] = clc_stc_cli_sti_std; | |
| ops_table[0xfd] = clc_stc_cli_sti_std; | |
| ops_table[0xfe] = inc_dec_rom8; | |
| ops_table[0xff] = inc_dec_call_jmp_push; | |
| FILE *f = fopen(argv[1], "rb"); | |
| u8 b; | |
| while(fread(&b, 1, 1, f)) ops_table[b](f, b); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment