Using Trainer and Instructions of Assembly language Control Traffic Light
Here are all the learning tasks grouped together with pointers to the example programs and explanatory notes.
Ø Improve the traffic lights data table so there is an overlap with both sets of lights on red.
Most of these examples include a learning task. Study the example and if you can complete the task/s, it is likely that your understanding is good.
Example – p # 7 Traffic control lights.asm
|; —– EXAMPLE ——-CONTROL TRAFIC LIGHTS————————– JMP Start ; Skip past the data table. DB 84 ; Data table begins. DB C8 ; These values control the traffic lights DB 31 ; This sequence is simplified. DB 58 ; Last entry is also used as end marker Start: MOV BL,02 ; 02 is start address of data tableRep: MOV AL,[BL] ; Copy data from table to AL OUT 01 ; Output from AL register to port 01 CMP AL,58 ; Last item in data table ??? JZ Start ; If yes then jump to Start INC BL ; In no then point BL to the next entry JMP Rep ; Jump back to do next table entry END; ————————————————————– TASK Improve the traffic lights data table so there is an overlap with both sets of lights on red. ; ————————————————————–|
You can copy this example program from the help page and paste it into the source code editor.
DB stands for Define Byte/s. In this case 84hex is stored into RAM at address . Addresses  and  are occupied by the JMP Start machine codes.
84 hex is 1000 0100 in binary. This is the pattern or noughts and ones needed to turn on the left red light and the right green light.
Move 02 into the BL register. [O2] is the RAM address of the start of the data table. BL is used as a pointer to the data table.
[BL] points to the data table. This line copies a value from the data table into the AL register.
Send the contents of the AL register to port 01. Port 01 is connected to the traffic lights.
58 is the last entry in the data table. If AL contains 58, it is necessary to reset BL to point back to the start of the table ready to repeat the sequence. If AL is equal to 58, the ‘Z’ flag in the CPU will be set.
Jump back to start if the ‘Z’ flag in the CPU is set.
Add one to BL to make it point to the next entry in the data table.
Figure #1 when light is green
Figure #2 when light is Red and going to green
MICROPROCESSOR PRACTICAL NOTE BOOK WRITER: MISS SABA WAHAB