YJDoc2 / 8086-Emulator

An Intel 8086 Emulator created in Rust.
Apache License 2.0
334 stars 49 forks source link

AAA Does not clear upper nibble #26

Open AshTS opened 6 months ago

AshTS commented 6 months ago

The algorithm performed by the ASCII Adjust After Addition instruction is documented as always clearing the upper nibble of AL. However, the current implementation does not do so.

From https://www.felixcloutier.com/x86/aaa:

IF 64-Bit Mode
    THEN
        #UD;
    ELSE
        IF ((AL AND 0FH) > 9) or (AF = 1)
            THEN
                AX := AX + 106H;
                AF := 1;
                CF := 1;
            ELSE
                AF := 0;
                CF := 0;
        FI;
        AL := AL AND 0FH;
FI;

This can be fixed by adding the bitwise and in the aaa implementation.