Walking thru the NAND program.
This example will use E4 [1110 0100] on PORT A

LDA $A001
1 1 1 0 0 1 0 0

STA $0300
Accumulator_A  1 1 1 0 0 1 0 0
RAM 0300 1 1 1 0 0 1 0 0

ASL A
Accumulator_A 1 1 0 0 1 0 0 0

AND $0300
Accumulator_A 1 1 0 0 1 0 0 0
RAM 0300 1 1 1 0 0 1 0 0
Accumulator_A 1 1 0 0 0 0 0 0

EOR #$AA (FF is just as good)
Accumulator_A 1 1 0 0 0 0 0 0
AA 1 0 1 0 1 0 1 0
Accumulator_A 0 X 1 X 1 X 1 X

The bits 0,2,4,6 are meaningless, therefore X is used.

STA $A000 [Output to Port B]
INPUT OUTPUT
Gate 1 A0,A1 B1
Gate 2 A2,A3 B3
Gate 3 A4,A5 B5
Gate 4 A6,A7 B7

NOTE: B0, B2, B4 B6 are not used.