Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the program to step the lights through a realistic sequence. Include cond

ID: 3551541 • Letter: M

Question

Modify the program to step the lights through a realistic sequence. Include conditional statements that ensure that assembly program only executes for 10 times.


; ===== 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.


Please show all steps!

Explanation / Answer

I will wirte R for Red A for Amber and G for Green

X is not connected

See i the traffic lights are connected like

R A G R A G X X

Realistic traffic light goes Red ---> some delay ----> Amber -----> some delay----> green ----> delay--back to red

now let us see what is hex representation for this sequence

1 means light is ON

0 means light is OFF


Only Red

R A G R A G X X

1 0 0 1 0 0 0 0 = hex 90


only amber

0 1 0 0 1 0 0 0   = hex 48


only green

0 0 1 0 0 1 0 0 = hex 24


for creating a delay we will set a procedure to decrement AL. since this takes time a delay is created.

The delay will depend on value in AL. Higher the value higher the delay.


for the count of 10 times we need to maintain a variable intialized to 10 or hex A and decrement it every time after we go throught the sequence Red ---> some delay ----> Amber -----> some delay----> green




; _____ THE REALISTIC 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).

    MOV    BL,0A    ; BL= ten

LOOP

                ; Turn on Red traffic lights.
    MOV    AL,90    ; Copy 10010000 into the AL register.
    OUT    01          ; Send AL to Port One (The traffic lights).

    MOV    AL,10    ; A middle sized delay.
    CALL    30   ; Call the procedure at address [30]. This will create a delay

; Turn on Amber traffic lights.
    MOV    AL,48    ; Copy 01001000 into the AL register.
    OUT    01          ; Send AL to Port One (The traffic lights).

    MOV    AL,10    ; A middle sized delay.
    CALL    30   ; Call the procedure at address [30]. This will create a delay

; Turn on Green traffic lights.
    MOV    AL,24    ; Copy 00100100 into the AL register.
    OUT    01          ; Send AL to Port One (The traffic lights).

    MOV    AL,10    ; A middle sized delay.
    CALL    30   ; Call the procedure at address [30]. This will create a delay
    DEC    BL    ; Subtract one from BL.
    JNZ    LOOP    ; Jump back to LOOP if BL was not Zero.


; ----- 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
; ---------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote