EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
45 stars 11 forks source link

test/6800.c The 6800 emulator does not correctly change the flags resulting from the CPX instruction. #78

Open zu2 opened 2 weeks ago

zu2 commented 2 weeks ago

The 6800 emulator does not correctly change the flags resulting from the CPX instruction.

The CPX instruction compares the upper and lower bytes separately. N and V only reflect the result of the comparison of the upper byte.

(The Z flag refers to both results, so it is a correct 16-bit equality comparison)

For documentation, see Motorola M6800 Programming Reference Manual A-33, 6800 Assembly Language Programming 3-50.

https://archive.org/details/bitsavers_motorola68rammingReferenceManualM68PRMDNov76_6944968/page/n65/mode/2up https://archive.org/details/6800-assembly-language-programming-lance-leventhal-1978/page/n91/mode/2up

Results of execution on the 6800 emulator. When comparing 0 and 1, both upper bytes are 0, so N should not be set. However, the emulator execution result shows N.

$ PATH=/opt/fcc/bin/:$PATH ./run-test6800.sh |head 0000-emu: 0100 : ----I- 00|00 0000 0000 | LDX #0000 0103 : --Z-I- 00|00 0000 0000 | CPX #0001 0106 : ---NI- 00|00 0000 0000 | NOP

EtchedPixels commented 2 weeks ago

6800 emulation looks at the top bit of the result of the comparison and upper compare only but computes the result for the entire 16bit and should only do so for the upper 8bit adds.

68HC11 CPY ,X and CPY , Y also appear to fail for a different reason (data16 is used where tmp16 is required)

EtchedPixels commented 2 weeks ago

Fixed in emulator needs propagating to compiler tests when emulator test work is done