8086 machine code, 22 20 bytes
8bd0 2bc3 740e 7902 f7d8 3d0500 7405 03d3 83fa05
Ungolfed:
ESD MACRO
LOCAL SUB_POS, DONE
MOV DX, AX ; Save AX to DX
SUB AX, BX ; AX = AX - BX
JZ DONE ; if 0, then they are equal, ZF=1
JNS SUB_POS ; if positive, go to SUB_POS
NEG AX ; otherwise negate the result
SUB_POS:
CMP AX, 5 ; if result is 5, ZF=1
JZ DONE
ADD DX, BX ; DX = DX + BX
CMP DX, 5 ; if 5, ZF=1
DONE:
ENDM
Input numbers in AX and BX and returns Zero Flag (ZF=1) if result is true. 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 ; result false
If the difference between the numbers is 0, we know they are equal. Otherwise if result is negative, then first negate it and then check for 5. If still not true, then add and check for 5.
Sample PC DOS test program. Download it here (ESD.COM).
START:
CALL INDEC ; input first number into AX
MOV BX, AX ; move to BX
CALL INDEC ; input second number into BX
ESD ; run "Equal, sum or difference" routine
JZ TRUE ; if ZF=1, result is true
FALSE:
MOV DX, OFFSET FALSY ; load Falsy string
JMP DONE
TRUE:
MOV DX, OFFSET TRUTHY ; load Truthy string
DONE:
MOV AH, 9 ; DOS display string
INT 21H ; execute
MOV AX, 4C00H ; DOS terminate
INT 21H ; execute
TRUTHY DB 'Truthy$'
FALSY DB 'Falsy$'
INCLUDE INDEC.ASM ; generic decimal input prompt routine
Output of test program:
A>ESD.COM
: 4
: 1
Truthy
A>ESD.COM
: 10
: 10
Truthy
A>ESD.COM
: 1
: 3
Falsy
A>ESD.COM
: 6
: 2
Falsy
A>ESD.COM
: 1
: 6
Truthy
A>ESD.COM
: -256
: -251
Truthy
A>ESD.COM
: 6
: 1
Truthy
A>ESD.COM
: 9999999999
: 9999999994
Truthy