perfaware/part1: Handle listing 0040

This commit is contained in:
doyle 2023-03-09 23:20:02 +11:00 committed by committed-name
parent c4e2be3926
commit 53ca69bfc5
2 changed files with 49 additions and 69 deletions

View File

@ -403,14 +403,14 @@ int main(int argc, char **argv)
} else { } else {
// NOTE: Memory mode w/ effective address calculation // NOTE: Memory mode w/ effective address calculation
// ========================================================= // =========================================================
bool direct_address = mod == 0b00 && rm == 0b110; bool direct_address = mod == 0b00 && rm == 0b110;
uint16_t displacement = 0; int16_t displacement = 0;
if (mod == 0b10 || direct_address) { // Mem mode 16 bit displacement if (mod == 0b10 || direct_address) { // Mem mode 16 bit displacement
uint8_t disp_lo = S86_BufferIteratorNextByte(&buffer_it); uint8_t disp_lo = S86_BufferIteratorNextByte(&buffer_it);
uint8_t disp_hi = S86_BufferIteratorNextByte(&buffer_it); uint8_t disp_hi = S86_BufferIteratorNextByte(&buffer_it);
displacement = (uint16_t)disp_lo << 0 | (uint16_t)disp_hi << 8; displacement = (int16_t)((uint16_t)disp_hi << 8 | (uint16_t)disp_lo << 0);
} else if (mod == 0b01) { // Mem mode 8 bit displacement } else if (mod == 0b01) { // Mem mode 8 bit displacement
displacement = S86_BufferIteratorNextByte(&buffer_it); displacement = (int8_t)S86_BufferIteratorNextByte(&buffer_it);
} else { } else {
S86_ASSERT(mod == 0b00 /*Mem mode (no displacement)*/); S86_ASSERT(mod == 0b00 /*Mem mode (no displacement)*/);
} }
@ -424,40 +424,30 @@ int main(int argc, char **argv)
if (direct_address) { if (direct_address) {
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size,
sizeof(effective_addr_buffer) - effective_addr_size, sizeof(effective_addr_buffer) - effective_addr_size,
"%u", "%s%d",
displacement); displacement >= 0 ? "" : "-", displacement >= 0 ? displacement : -displacement);
} else { } else {
if (rm == 0b110) { S86_Str8 base_calc = {0};
effective_addr_buffer[effective_addr_size++] = 'b'; switch (rm) {
effective_addr_buffer[effective_addr_size++] = 'p'; case 0b000: base_calc = S86_STR8("bx + si"); break;
if (displacement) { case 0b001: base_calc = S86_STR8("bx + di"); break;
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, case 0b010: base_calc = S86_STR8("bp + si"); break;
sizeof(effective_addr_buffer) - effective_addr_size, case 0b011: base_calc = S86_STR8("bp + di"); break;
" + %u", case 0b100: base_calc = S86_STR8("si"); break;
displacement); case 0b101: base_calc = S86_STR8("di"); break;
} case 0b110: base_calc = S86_STR8("bp"); break;
} else { case 0b111: base_calc = S86_STR8("bx"); break;
S86_Str8 base_calc = {0}; default: S86_ASSERT(!"Invalid rm value, must be 3 bits"); break;
switch (rm) { }
case 0b000: base_calc = S86_STR8("bx + si"); break;
case 0b001: base_calc = S86_STR8("bx + di"); break;
case 0b010: base_calc = S86_STR8("bp + si"); break;
case 0b011: base_calc = S86_STR8("bp + di"); break;
case 0b100: base_calc = S86_STR8("si"); break;
case 0b101: base_calc = S86_STR8("di"); break;
case 0b111: base_calc = S86_STR8("bx"); break;
default: S86_ASSERT(!"Invalid rm value, must be 3 bits"); break;
}
memcpy(effective_addr_buffer + effective_addr_size, base_calc.data, base_calc.size); memcpy(effective_addr_buffer + effective_addr_size, base_calc.data, base_calc.size);
effective_addr_size += S86_CAST(int)base_calc.size; effective_addr_size += S86_CAST(int)base_calc.size;
if (mod == 0b01 || mod == 0b10) { if ((mod == 0b01 || mod == 0b10) && displacement) {
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size,
sizeof(effective_addr_buffer) - effective_addr_size, sizeof(effective_addr_buffer) - effective_addr_size,
" + %u", " %c %d",
displacement); displacement >= 0 ? '+' : '-', displacement >= 0 ? displacement : -displacement);
}
} }
} }
effective_addr_buffer[effective_addr_size++] = ']'; effective_addr_buffer[effective_addr_size++] = ']';
@ -485,13 +475,13 @@ int main(int argc, char **argv)
// NOTE: Memory mode w/ effective address calculation // NOTE: Memory mode w/ effective address calculation
// ========================================================= // =========================================================
bool direct_address = mod == 0b00 && rm == 0b110; bool direct_address = mod == 0b00 && rm == 0b110;
uint16_t displacement = 0; int16_t displacement = 0;
if (mod == 0b10 || direct_address) { // Mem mode 16 bit displacement if (mod == 0b10 || direct_address) { // Mem mode 16 bit displacement
uint8_t disp_lo = S86_BufferIteratorNextByte(&buffer_it); uint8_t disp_lo = S86_BufferIteratorNextByte(&buffer_it);
uint8_t disp_hi = S86_BufferIteratorNextByte(&buffer_it); uint8_t disp_hi = S86_BufferIteratorNextByte(&buffer_it);
displacement = (uint16_t)disp_lo << 0 | (uint16_t)disp_hi << 8; displacement = (int16_t)((uint16_t)disp_lo << 0 | (uint16_t)disp_hi << 8);
} else if (mod == 0b01) { // Mem mode 8 bit displacement } else if (mod == 0b01) { // Mem mode 8 bit displacement
displacement = S86_BufferIteratorNextByte(&buffer_it); displacement = (int8_t)S86_BufferIteratorNextByte(&buffer_it);
} else { } else {
S86_ASSERT(mod == 0b00 /*Mem mode (no displacement)*/); S86_ASSERT(mod == 0b00 /*Mem mode (no displacement)*/);
} }
@ -513,40 +503,30 @@ int main(int argc, char **argv)
if (direct_address) { if (direct_address) {
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size,
sizeof(effective_addr_buffer) - effective_addr_size, sizeof(effective_addr_buffer) - effective_addr_size,
"%u", "%s%d",
displacement); displacement >= 0 ? "" : "-", displacement >= 0 ? displacement : -displacement);
} else { } else {
if (rm == 0b110) { S86_Str8 base_calc = {0};
effective_addr_buffer[effective_addr_size++] = 'b'; switch (rm) {
effective_addr_buffer[effective_addr_size++] = 'p'; case 0b000: base_calc = S86_STR8("bx + si"); break;
if (displacement) { case 0b001: base_calc = S86_STR8("bx + di"); break;
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, case 0b010: base_calc = S86_STR8("bp + si"); break;
sizeof(effective_addr_buffer) - effective_addr_size, case 0b011: base_calc = S86_STR8("bp + di"); break;
" + %u", case 0b100: base_calc = S86_STR8("si"); break;
displacement); case 0b101: base_calc = S86_STR8("di"); break;
} case 0b110: base_calc = S86_STR8("bp"); break;
} else { case 0b111: base_calc = S86_STR8("bx"); break;
S86_Str8 base_calc = {0}; default: S86_ASSERT(!"Invalid rm value, must be 3 bits"); break;
switch (rm) { }
case 0b000: base_calc = S86_STR8("bx + si"); break;
case 0b001: base_calc = S86_STR8("bx + di"); break;
case 0b010: base_calc = S86_STR8("bp + si"); break;
case 0b011: base_calc = S86_STR8("bp + di"); break;
case 0b100: base_calc = S86_STR8("si"); break;
case 0b101: base_calc = S86_STR8("di"); break;
case 0b111: base_calc = S86_STR8("bx"); break;
default: S86_ASSERT(!"Invalid rm value, must be 3 bits"); break;
}
memcpy(effective_addr_buffer + effective_addr_size, base_calc.data, base_calc.size); memcpy(effective_addr_buffer + effective_addr_size, base_calc.data, base_calc.size);
effective_addr_size += S86_CAST(int)base_calc.size; effective_addr_size += S86_CAST(int)base_calc.size;
if (mod == 0b01 || mod == 0b10) { if ((mod == 0b01 || mod == 0b10) && displacement) {
effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size, effective_addr_size += snprintf(effective_addr_buffer + effective_addr_size,
sizeof(effective_addr_buffer) - effective_addr_size, sizeof(effective_addr_buffer) - effective_addr_size,
" + %u", " %c %d",
displacement); displacement >= 0 ? '+' : '-', displacement >= 0 ? displacement : -displacement);
}
} }
} }
effective_addr_buffer[effective_addr_size++] = ']'; effective_addr_buffer[effective_addr_size++] = ']';

Binary file not shown.