8051 microcontroller assembly language elevator coding
Design first, code later. Plan everything out using logic, flow diagrams, state diagrams, etc. Your problems are with the logic, not the coding. Jonk has done 8051, I have not. I have done 6502 and 6800 assembly, these are similar.

At first you might be tempted to have states based on physical position.



But, an elevator really only has 3 states, going up, going down, stopped.



This is only one possible design, there are other valid designs. I have made some assumptions, if I got some wrong, you may need to scrap all this and start over. 

All of your buttons and sensors are momentary, you need variables to remember the previous (last) button/sensor activated for each of these. A variable can be stored in a memory location or a register. I have used long descriptive names, in assembler you probably want shorter names.

Floor_Selected: a variable to remember what floor the user has selected. I have assumed a queue of one. 

Last_Floor_Sensor: a variable to remember what floor sensor was activated last.

The third is not as obvious, but without it, the elevator will switch directions mid-floor, you probably don't want that.

Next_Floor_Selected: If the elevator is in motion, remember where to go next.

You also need a variable to represent the state of the elevator:
Elev_State: let: Stop = 0, Up = 1, Down = 2

Now, the basic flow:

Floor_Selected = 0
Next_Floor_Selected = 0
Last_Floor_Sensor = 0
Elev_State = Stop

Loop
{
    Read all buttons, save active button in Next_Floor_Selected variable
    If Elev_State = Stop   // Only allow the next command when stopped 
       Floor_Selected = Next_Floor_Selected 

    Read all sensors, save active sensor in Last_Floor_Sensor variable

    Update state based on diagram. Set motor direction based on state 
}


Notes:

The loop must be iterated fast, the buttons and sensor must be polled fast.

If multiple buttons are pressed at the same time, you will need to arbitrarily prioritize them. It doesn't really matter, the last button released will get priority.

I have guessed on some of the logic details. As it is, the next floor is in a queue, the car will travel to the next floor selected, it will not stop at in-between floors.

The preempt logic that was added to prevent reversals mid-floor has a downside, if the elevator starts at floor 0, floor 2 button is pressed, elevator starts moving toward floor 1, if button 1 is pressed before it gets to floor 1, a real elevator will stop at floor 1; With this logic, it will not.

Before you code, test the logic by stepping through it manually. Test multiple scenarios until you are sure that it does what you want. Then code.