x86-16 machine code, 21 20 bytes
00000000: 8bd0 2bc3 740d 7902 f7d8 3c05 7405 03d3 ..+.t.y...<.t...
00000010: 80fa 05c3 ....
Listing:
8B D0 MOV DX, AX ; Save AX to DX
2B C3 SUB AX, BX ; AX = AX - BX
74 0D JZ DONE ; if 0, they are equal (ZF=1)
79 02 JNS IS_POS ; if positive, check if result is 5
F7 D8 NEG AX ; is negative, negate the result to get abs value
IS_POS:
3C 05 CMP AL, 5 ; is result 5?
74 05 JZ DONE ; if so, exit with ZF=1
03 D3 ADD DX, BX ; DX = DX + BX
80 FA 05 CMP DL, 5 ; ZF = ( DX == 5 )
DONE:
C3 RET ; return to caller
Input numbers in AX
and BX
and returns Zero Flag (ZF
) if result is truthy.
Try it online! (testing code borrowed and adapted from @Logem's answer - thanks!)
Explanation:
If the difference between the numbers is 0, they are equal. Otherwise if result is negative, first negate it (abs value) and check for 5. If still not true, add and check for 5.
Bonus:
If desired, you can also determine which condition was true with the following:
ZF
= 1
and DX
= 5
; sum is 5
ZF
= 1
and AX
= 5
; diff is 5
ZF
= 1
and AX
= 0
; equal
ZF
= 0
; falsey