checking two input pin states in assembly
I am coding in assembly.
I have two input pins I am interested in, lets say pin 5 and 6.
The other inputs are in unknown states... I have not tied them to ground, and many are for peripherals since I'm using a development board.
I'm using "and" to mask the inputs I care about, and then "xor" with "wz" to determine if the bits I care about are set.
Here's an example:
Is this a good way to do it, or is there a better way?
Thanks
Ion
I have two input pins I am interested in, lets say pin 5 and 6.
The other inputs are in unknown states... I have not tied them to ground, and many are for peripherals since I'm using a development board.
I'm using "and" to mask the inputs I care about, and then "xor" with "wz" to determine if the bits I care about are set.
Here's an example:
mov temp1, ina 'Get the current inputs
and temp1, bothInputs 'Mask the inputs I care about
xor temp1, bothInputs wz,nr 'Check if both inputs are high
if_z jmp #BothInputsAreHigh
xor temp1, justInput5 wz,nr 'Check if just input 5 is high
if_z jmp #JustInput5IsHigh
bothInputs long %110_0000
justInput5 long %010_0000
temp1 long 0
Is this a good way to do it, or is there a better way?
Thanks
Ion

Comments
test bothInputs,ina wz,wc 'Mask the inputs I care about if_z jmp #BothInputsAreLow if_nz_and_nc jmp #BothInputsAreHigh 'Carry is cleared if an even number of bits is set if_nz_and_c jmp #OneInputsIsHigh 'Carry is set if an odd number of bits is set test justInput5,ina wz 'Check if just input 5 is high if_nz jmp #JustInput5IsHigh if_z jmp #Input5IsLow ' for waiting until inputs are set: waitpeq bothInputs,bothInputs 'Wait until both are set waitpne bothInputs,bothInputs 'Wait until one or both are clearedThe test for both inputs by the Carry works only with 2 inputs, if you have more bits, then your methode with xor is the right one.
And be aware that:
test maskreg,ina is not the same as test ina,maskreg
the second does not work as expected, because the INA has to be the source register.
Andy