perfaware/part1: Support listing 0048

This commit is contained in:
doyle 2023-04-16 21:36:10 +10:00
parent 20be5d0892
commit 6f0715b0ca
4 changed files with 34 additions and 14 deletions

View File

@ -153,7 +153,7 @@ set build_dir_listing_0048=%build_dir%\%listing_0048%
copy /Y %script_dir%\%listing_0048% %build_dir% 1>NUL
copy /Y %script_dir%\%listing_0048%.txt %build_dir% 1>NUL
%build_dir%\sim8086.exe --exec %build_dir_listing_0048% > %build_dir_listing_0048%_disassembled.txt
%build_dir%\sim8086.exe --exec --log-instruction-ptr %build_dir_listing_0048% > %build_dir_listing_0048%_disassembled.txt
%build_dir%\sim8086.exe %build_dir_listing_0048% > %build_dir_listing_0048%_disassembled.asm
nasm %build_dir_listing_0048%_disassembled.asm

View File

@ -332,6 +332,7 @@ S86_Opcode S86_DecodeOpcode(S86_BufferIterator *buffer_it,
bool *lock_prefix,
S86_MnemonicOp *seg_reg)
{
size_t buffer_start_index = buffer_it->index;
char op_code_bytes[2] = {0};
size_t op_code_size = 0;
op_code_bytes[op_code_size++] = S86_BufferIteratorNextByte(buffer_it);
@ -815,6 +816,8 @@ S86_Opcode S86_DecodeOpcode(S86_BufferIterator *buffer_it,
if (op_decode_type != S86_OpDecodeType_SEGMENT)
*seg_reg = S86_MnemonicOp_Invalid;
size_t buffer_end_index = buffer_it->index;
result.byte_size = S86_CAST(uint8_t)(buffer_end_index - buffer_start_index);
return result;
}
@ -1207,6 +1210,8 @@ int main(int argc, char **argv)
{.mnemonic_op = S86_MnemonicOp_DS, .mnemonic_op_reg16 = S86_MnemonicOp_DS, .reg = &register_file.ds, .byte = S86_RegisterByte_Nil},
};
// NOTE: Count opcodes, allocate then decode in 1 swoop
// =========================================================================
S86_Opcode *opcode_array = NULL;
size_t opcode_size = 0;
{
@ -1235,6 +1240,8 @@ int main(int argc, char **argv)
}
}
// NOTE: Execute the assembly
// =========================================================================
for (size_t opcode_index = 0; opcode_index < opcode_size; opcode_index++) {
S86_Opcode *opcode = opcode_array + opcode_index;
S86_PrintOpcode(*opcode);
@ -1479,9 +1486,16 @@ int main(int argc, char **argv)
S86_PrintFmt(" ; %.*s:0x%x->0x%x ", S86_STR8_FMT(dest_reg16), prev_dest.word, dest.word);
*dest_map->reg = dest;
}
} break;
}
// NOTE: Print Instruction Pointer
if (log_instruction_ptr)
S86_PrintFmt("ip:0x%x->0x%x ", register_file.instruction_ptr, register_file.instruction_ptr + opcode->byte_size);
register_file.instruction_ptr += opcode->byte_size;
// NOTE: Print Flags
if (!S86_RegisterFileFlagsEq(register_file.flags, prev_flags)) {
S86_PrintFmt("flags:");
if (prev_flags.carry)
@ -1512,6 +1526,7 @@ int main(int argc, char **argv)
S86_PrintFmt("O");
S86_PrintFmt(" ");
}
S86_Print(S86_STR8("\n"));
}
@ -1540,6 +1555,9 @@ int main(int argc, char **argv)
if (register_file.ds.word)
S86_PrintLnFmt(" ds: 0x%04x (%u)", register_file.ds, register_file.ds);
if (log_instruction_ptr)
S86_PrintLnFmt(" ip: 0x%04x (%u)", register_file.instruction_ptr, register_file.instruction_ptr);
S86_RegisterFileFlags nil_flags = {0};
if (!S86_RegisterFileFlagsEq(register_file.flags, nil_flags)) {
S86_PrintFmt(" flags: ");

View File

@ -322,6 +322,7 @@ typedef enum S86_WidePrefix {
} S86_WidePrefix;
typedef struct S86_Opcode {
uint8_t byte_size; ///< Number of bytes used to encode this opcode
S86_Mnemonic mnemonic; ///< Mnemonic type
S86_EffectiveAddress effective_addr; ///< Src/dest op is an effective address calculation
bool effective_addr_loads_mem; ///< Effective address uses '[]' notation to load address memory
@ -360,6 +361,7 @@ typedef struct S86_RegisterFileFlags {
typedef struct S86_RegisterFile {
S86_RegisterFileFlags flags;
uint16_t instruction_ptr;
S86_Register16 ax;
S86_Register16 bx;

Binary file not shown.