8086 d bit in opcode 1: what is the more common value, 0 or 1?

236 views Asked by At

For quite a lot of 8086 instructions, bit 1 of opcode 1 is a direction bit d (not to be confused with the DF flag), allowing two ways to encode the same instruction.

An emulator I am writing can decode 'from' and 'to' for either d=0 or d=1 but not both, due to space constraints. The undecoded value of d is handled by swapping 'from' and 'to', making it slower.

Does DOS in particular use d=0 in preference to d=1, or vice-versa?

1

There are 1 answers

0
Peter Cordes On

Only reg-reg instructions have a choice; then it probably depends on the assembler. (So beware of sample bias if you only profile a few executables with your emulator to get counts.)

I'd guess modern compiler-generated code will more often use memory-source operands like add reg, [esp+12] or something, but for 16-bit hand-written it could really go either way. Beginner code seen on Stack Overflow shows a large tendency to use craptastic static storage ("named variables") instead of registers.

As for DOS itself, I'd really recommend just profiling some typical uses with your emulator to find out what those binaries really do.

Add a counter to your emulator to record how many times you took the "fast" vs. "slow" ways. If it turns out you took the slow way a lot more, rewrite the code to make that the fast path.