Generally, most of this forum's members don't provide solutions when it appears that it is a homework problem. However, it appears that you've made an attempt to solve this problem, so I'll provide you a few pointers.
First, you need to look into the instruction set a bit more carefully. This problem has a fairly straight forward solution. Many years ago, my lab partners and I, pressed for time, solved a similar problem on an old SDK-85 trainer board. However, our solution required virtually all of the available memory in the device. We thought we were kind of special since we were the only ones to complete the assignment. The professor quickly brought us back down to earth when he presented the solution in class as an in-line solution of 16 instructions versus our solution of nearly 256 bytes.
Your initialization is correct, except for one nit picky issue. You use a CLI instruction to enable interrupts, but don't don't include an interrupt service routine in your code. You are also using two different styles for the definitions of your hexadecimal constants. Some assemblers recognize and support multiple styles, but I recommend using a single style throughout any one program.
Now to your approach. In general, the approach you have selected is not incorrect. However, the solution does not require any loops or complex masks as you have implemented. To arrive at the optimal solution, you will need to review the problem statement. The clue to the solution is right in the problem statement that you posted along with your code.
There is one important concept missing from your solution and that is how to toggle an LED.
You have isolated the switch using an active low mask because the switch is apparently closed to ground, and sensed by the processor as a logic 0. Dealing with active low or negative logic will be with you in any hardware design or programming you may do in your career. However, I've learned that it's easy to fall into a logical trap when mixing active low and active high signals.
Therefore, my recommendation is that all asserted signals be converted into a common basis. The processor that you are working with uses a logic 1 as the asserted state for its instructions and internal signals. This means that you need to isolate the switches with a mask, and then convert all 0s into 1s and vice-versa. There is a specific instruction in the 6502 instruction set for doing this required operation.
Quote:
It is supposed to read a latch that reflects the status of four switches (high nibble) and depending on which key is pressed, toggle the led at the low order nibble at the same address.
Second, you need to re-read the problem statement and then look for specific instructions or short sequences of instructions that will allow you move the bits of the inverted switches into alignment with the LEDs. Once this is accomplished, you only need to use a single instruction to toggle the state of the LEDs, store the resulting value into the zp working register you have already allocated, and then write that same value to the LED output register.
I have written a solution for this problem, and the solution does not require any loops over the bits representing the switches, and it only requires approximately 10 instructions and 19 bytes for the main program loop.
Hope this helps.
PS: A final solution may also require the switch debouncing that Garth alludes to in his response. I will assume for this excercise that the trainer that you are working with is taking care of this critical issue for you at this time.