1-1 now outputs to file

This commit is contained in:
Hane 2026-01-23 20:51:39 +01:00
commit 5f9c6a8fdf
2 changed files with 9 additions and 5 deletions

Binary file not shown.

View file

@ -4,9 +4,9 @@
enum DT_INSTRUCTIONS
{
MOV_RM_TF_R = 0b1000'10, //d w
MOV_RM_TF_R = 0b1000'10, //d w
MOV_I_T_RM = 0b1100'011, // w
MOV_I_T_R = 0b1011, // w reg
MOV_I_T_R = 0b1011, // w reg
MOV_M_T_A = 0b1010'000, // w
MOV_A_T_M = 0b1010'001, // w
MOV_RM_T_SR = 0b1000'1110,
@ -54,6 +54,7 @@ typedef struct
uint64_t size;
} binary_data;
FILE *output;
void MOV_RM_TF_R_parse(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
{
@ -67,8 +68,9 @@ void MOV_RM_TF_R_parse(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte
bool reg_is_dest = (byte1 & dest_mask);
//if D=1, dest is retrieved from the reg field in byte2 and src from r/m
uint8_t dest_value = (reg_is_dest) ? ((byte2 & regm_mask) >> 3) + ((byte1 & wide_mask) * 8) : (byte2 & (regm_mask >> 3)) + ((byte1 & wide_mask) * 8);
uint8_t src_value = (reg_is_dest) ? (byte2 & (regm_mask >> 3)) + ((byte1 & wide_mask) * 8) : ((byte2 & regm_mask) >> 3) + ((byte1 & wide_mask) * 8);
printf("%s, %s\n", REG_ENCODING_TXT[dest_value], REG_ENCODING_TXT[src_value]);
uint8_t src_value = (reg_is_dest) ? (byte2 & (regm_mask >> 3)) + ((byte1 & wide_mask) * 8) : ((byte2 & regm_mask) >> 3) + ((byte1 & wide_mask) * 8);
printf("%s %s, %s\n", "mov", REG_ENCODING_TXT[dest_value], REG_ENCODING_TXT[src_value]);
fprintf(output, "%s %s, %s\n", "mov", REG_ENCODING_TXT[dest_value], REG_ENCODING_TXT[src_value]);
return;
}
@ -83,6 +85,9 @@ int main(int argc, char** argv)
fseek(bin.binary, 0, SEEK_END);
bin.size = ftell(bin.binary);
fseek(bin.binary, 0, SEEK_SET);
output = fopen("output.asm", "w");
fprintf(output, "%s\n\n", "bits 16");
for (int bytes_read = 0; bytes_read < bin.size; bytes_read++)
{
@ -92,7 +97,6 @@ int main(int argc, char** argv)
//For now we're just checking for RM_TF_R
manip_inst = (manip_inst >> 2);
if (manip_inst != MOV_RM_TF_R) break;
printf("%s ", "mov");
if (bytes_read >= bin.size) break;
fread(byte, sizeof(byte), 1, bin.binary);
bytes_read++;