title: How to re-structure this code to be more efficient? 8086 Lift Simulator
body: <p>How would I change this code around to be more efficient or even different in any way? Would it be a good idea to use procedures rather than loops, anything to cut down on the RAM usage, as I'm really struggling. The lift simulator basically needs to go up and down again without crashing.</p>
  
  <pre><code>; ------------------------ THE LIFT ----------------------------
  Start:
  CLO
  OR  AL, 00 
  OUT 06      ; Display lift window
  
  ; --------------------------------------------------------------
  ; A LOOP THAT CONTROLS THE LIFT WHEN IDLE
  Idle:
  IN  06      ; Read lift status
  AND AL, 20      ; Isolate UP button bit
  JNZ Up      ; If UP button pressed, jump to UP
  IN  06      ; Read lift status
  AND AL, 10      ; Isolate DOWN button bit
  JNZ Down        ; If DOWN button pressed, jump to DOWN
  JMP Idle        ; Jump back to Idle
  
  ; --------------------------------------------------------------
  ; A LOOP TO CONTROL THE LIFT WHEN GOING UP
  Up:
  MOV AL, 21      ; Move hex value 21 to AL
  OUT 06      ; Display lift status
  MOV [AF], AL    ; Move contents of AL to RAM location AF
  IN  06      ; Read lift status
  AND AL, 4       ; Clear Bit 4 for use
  JNZ Stop        ; Stop if lift is close enough
  MOV AL, [AF]    ; Move contents of RAM location AF to AL
  JMP Idle        ; Jump back to Idle
  
  ; --------------------------------------------------------------
  ; A LOOP TO CONTROL THE LIFT WHEN GOING DOWN
  Down:
  MOV AL, 12      ; Move hex value 12 to AL
  OUT 06      ; Display the lift status
  MOV [AF], AL    ; Move contents of AL to RAM location AF
  IN  06      ; Read lift status
  AND AL, 8       ; Clear Bit 8 for use
  JNZ Stop        ; Stop if lift is close enough
  MOV AL, [AF]    ; Move contents of RAM location AF to AL
  JMP Idle        ; Jump back to Idle
  
  ; --------------------------------------------------------------
  ; A PROCEDURE TO STOP THE LIFT AT THE TOP AND BOTTOM
  Stop:
  MOV AL, AF      ; 
  MOV AL, 0       ; 
  OUT 06      ;
  JMP Idle
  
  ; --------------------------------------------------------------
  END
  ; --------------------------------------------------------------
  </code></pre>