Direct Address special case added(MOD 0 R/M 110)
This commit is contained in:
parent
2a92f04836
commit
5b2542b0dd
14
decode.c
14
decode.c
@ -147,18 +147,20 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
// This is a trick because mod == 1 and mod == 2 will displace one and two bytes
|
// This is a trick because mod == 1 and mod == 2 will displace one and two bytes
|
||||||
// respectively but mod == 3 wraps to 0 since it doesn't displace
|
// respectively but mod == 3 wraps to 0 since it doesn't displace
|
||||||
int bytes_to_read = mod % 3;
|
bool is_direct_addr = mod == 0 && rm == 0b110;
|
||||||
|
int bytes_to_read = is_direct_addr ? 2 : mod % 3;
|
||||||
bytes_read = fread(buf, sizeof(char), bytes_to_read, f);
|
bytes_read = fread(buf, sizeof(char), bytes_to_read, f);
|
||||||
char* eac_name = get_eac_registers(rm);
|
char* eac_name = is_direct_addr ? "" : get_eac_registers(rm);
|
||||||
char disp_buf[16] = {'\0'};
|
char disp_buf[16] = {'\0'};
|
||||||
if (bytes_to_read > 0)
|
if (bytes_to_read > 0)
|
||||||
{
|
{
|
||||||
i16 disp = get_data(buf, bytes_to_read - 1);
|
i16 disp = get_data(buf, bytes_to_read - 1);
|
||||||
sprintf(disp_buf, " %s %hd", disp >= 0 ? "+" : "-", abs(disp));
|
if (is_direct_addr) sprintf(disp_buf, "%d", abs(disp));
|
||||||
|
else sprintf(disp_buf, " %s %d", disp >= 0 ? "+" : "-", abs(disp));
|
||||||
}
|
}
|
||||||
Register reg = registers[reg_idx];
|
Register rgstr = registers[reg_idx];
|
||||||
if (d) printf("mov %s, [%s%s] ;1", reg_name(reg, w), eac_name, disp_buf);
|
if (d) printf("mov %s, [%s%s] ;1", reg_name(rgstr, w), eac_name, disp_buf);
|
||||||
else printf("mov [%s%s], %s ;2", eac_name, disp_buf, reg_name(reg, w));
|
else printf("mov [%s%s], %s ;2", eac_name, disp_buf, reg_name(rgstr, w));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Immediate to register/memory
|
// Immediate to register/memory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user