3 ms·
Don't forget the direction bit in the 8086's status register. [Don't forget the decimal mode bit in the 6502's status register :-)]
by kabdib 4y ago
Don't forget the direction bit in the 8086's status register.
[Don't forget the decimal mode bit in the 6502's status register :-)]
- chrononaut 4y agoWhat's noteworthy about the decimal mode bit in OP's example? (Not familiar with 6502 nuances, so this sounds interesting.)
- ataylor284_ 4y agoThey're both called the "D" flag, and they both globally control the behavior of certain processor instructions. Besides that, they're totally different. The 8086 D flag is the direction for string instructions, whether to increment or decrement the index registers after each repetition. One use was for moving memory between overlapping regions by starting at the end and working backwards. The 6502 D flag is for decimal mode. When set, the instructions ADC and SBC do BCD arithmetic instead of binary, e.g. 0x09 + 0x01 = 0x10 instead of 0x0A as you'd expect. The 8086 also has support for BCD, but took a different approach, using separate instructions DAA/DAS for the same purpose. Both can lead to bugs when you assume the flag is in the "normal" state but it somehow got flipped.
- ataylor284_ 4y agoLearned that one the hard way. I built a 6502 single board computer and tested it out running my customer built monitor. I spent hours verifying the hardware to isolate a problem where programs would crash and memory would become corrupted. Turns out my monitor was popping garbage into the flags register when it returned control and sometimes setting decimal mode.