The SWAP command swaps the values of two variables. The CY<2 and CY>0 make sure that the blank space is inside the box after the move. So, if you press right on the D-Pad, it checks to see if the blank space is greater than zero. If the value is true, the it will swap the values of the blank space with the one to the left of it. Then it will move the blank space one to the left with CX=CX-1.