Site Logo

Example - 02tlight.asm - Traffic Lights

Website

Home | Previous | Next

Example - 02tlight.asm


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

	YOUR TASK
	=========
	Use the help page on Hexadecimal and ASCII codes.
	Work out what hexadecimal numbers will activate the
	correct traffic lights. Modify the program to step
	the lights through a realistic sequence.

 

To run the program press the Step button repeatedly or press the Run button.

To stop the program, press Stop. When the program is running, click the RAM-Source or RAM-Hex or RAM-ASCII tabs. These give alternative views of the contents of random access memory (RAM).

Also click the List File tab to see the machine code generated by the simulator and the addresses where the codes are stored.

Ports

The traffic lights are connected to port one. Imagine this as a socket on the back of the processor box. Data sent to port one goes to the traffic lights and controls them.

There are six lamps to control. Red, Amber and Green for a pair of lights. This can be achieved with a single byte of data where two bits are unused.

By setting the correct bits to One, the correct lamps come on.

Traffic Lights Image

Fill in the rest of this table to work out the Hexadecimal values you need. Of course you need to know the sequence of lights in your country.

Red
Amber
Green
Red
Amber
Green
Unused
Unused
Hexadecimal
1
0
0
0
0
1
0
0
84
                 
                 
                 

 

What you need to know

Labels and Jumps

Labels mark positions that are used by Jump commands. All the commands in this program are repeated for ever or until Stop is pressed. Label names must start with a letter or _ character. Label names must not start with a digit. The line


JMP Start

causes the program to jump back and re-do the earlier commands.

Destination labels end in a colon. For example


Start:

Controlling the Lights

If you look carefully at the traffic lights display, you can see which bit controls each light bulb. Work out the pattern of noughts and ones needed to turn on a sensible set of bulbs. Use the Hexadecimal and Binary numbers table to work out the hexadecimal equivalent. Move this hexadecimal number into AL.


OUT 01

This command copies the contents of the AL register to Output Port One. The traffic lights are connected to port one. A binary one causes a bulb to switch on. A nought causes it to turn off.

Home | Previous | Next

© C Neil Bauers 2003