this is my code for a traffic light, i cant figure out how to make it loop 10 ti
ID: 3552667 • Letter: T
Question
this is my code for a traffic light, i cant figure out how to make it loop 10 times and then end.
CLO ; Close unwanted windows .
MOV BL,0
Start:
; Turn off all the traffic lights.
CMP BL,3
ADD BL,1
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,80 ; Copy 10000000 into the AL register.
OUT 01
MOV AL,40 ; Copy 01000000 into the AL register.
OUT 01
MOV AL,20 ; Copy 00100000 into the AL register.
OUT 01
MOV AL,10 ; Copy 00010000 into the AL register.
OUT 01
MOV AL,8 ; Copy 00001000 into the AL register.
OUT 01
MOV AL,4 ; Copy 00000100 into the AL register.
OUT 01
; Send AL to Port One (The traffic lights).
JMP Start ; Jump back to the start.
END ; Program ends.
Explanation / Answer
One of the format
MOV CL, 10
L1:
<LOOP-BODY>
DEC CL
JNZ L1
So whole program will be
CLO ; Close unwanted windows .
MOV BL,0
Start:
MOV CL, 10
L1:
CMP BL,3
ADD BL,1
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,80 ; Copy 10000000 into the AL register.
OUT 01
MOV AL,40 ; Copy 01000000 into the AL register.
OUT 01
MOV AL,20 ; Copy 00100000 into the AL register.
OUT 01
MOV AL,10 ; Copy 00010000 into the AL register.
OUT 01
MOV AL,8 ; Copy 00001000 into the AL register.
OUT 01
MOV AL,4 ; Copy 00000100 into the AL register.
OUT 01; Send AL to Port One (The traffic lights).
DEC CL
JNZ L1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.