; ---------------------------------------------------------------
; A general purpose time delay procedure.
; The delay is controlled by the value in AL.
; When the procedure terminates, the CPU registers are
; restored to the same values that were present before
; the procedure was called. Push, Pop, Pushf and Popf
; are used to achieve this. In this example one procedure
; is re-used three times. This re-use is one of the main
; advantages of using procedures.
;------ The Main Program ----------------------------------------
Start:
MOV AL,8 ; A short delay.
CALL 30 ; Call the procedure at address [30]
MOV AL,10 ; A middle sized delay.
CALL 30 ; Call the procedure at address [30]
MOV AL,20 ; A Longer delay.
CALL 30 ; Call the procedure at address [30]
JMP Start ; Jump back to the start.
; ----- Time Delay Procedure Stored At Address [30] -------------
ORG 30 ; Generate machine code from address [30]
PUSH AL ; Save AL on the stack.
PUSHF ; Save the CPU flags on the stack.
Rep:
DEC AL ; Subtract one from AL.
JNZ REP ; Jump back to Rep if AL was not Zero.
POPF ; Restore the CPU flags from the stack.
POP AL ; Restore AL from the stack.
RET ; Return from the procedure.
; ---------------------------------------------------------------
END
; ---------------------------------------------------------------
TASK
Re-do the traffic lights program and use this procedure
to set up realistic time delays. 02tlight.asm (See below)
; ===== CONTROL THE TRAFFIC LIGHTS =============================
CLO ; Close unwanted windows.
Start:
; Turn off all the traffic lights.
MOV AL,0 ; Copy 00000000 into the AL register.
OUT 01 ; Send AL to Port One (The traffic lights).
; Turn on all the traffic lights.
MOV AL,FC ; Copy 11111100 into the AL register.
OUT 01 ; Send AL to Port One (The traffic lights).
JMP Start ; Jump back to the start.
END ; Program ends.
; ===== Program Ends ==========================================
0 comments