(14-07-10)+Computer+Architecture-Written+by+Kieron+Edwards+(WC6137)+NC

= = toc
 * Unit 9, Computer Architecture (NC System Support) **

__Introduction__
To become a Junior Systems Design Engineer with Automated Control Systems Ltd a number of tasks have been assigned to the application as part of the selection process, they will be presented in report form in the following document. =__ Task 1 __=

__Subtask 1.1__
Subtask 1.1 describes how numeric and alphanumeric data can be coded within a computer system.

__Decimal and Binary__
A number system is a set of characters used to represent a mathematical value, the characters can be either numeric (numbers) or alphanumeric (numbers and letters). Although there are many different number systems, humans normally use the decimal number system (also known as denary number system). In the decimal number system, ten characters are used (0-9) this said to have a base of 10 (also known as a radix of 10). Computers however use a base 2 number system called binary. The two characters used are 1 and 0. The binary number system was chosen to be used with computers because a transmitted signal can be either on or off, this can therefore be represented as 1 or 0 as in binary. Binary was also chosen as it has a wide margin of error in comparison to, for example, decimal. A transmitted signal can be either on or off, however because analogue signals travel in a wave form (see below). If decimal was used, ten different values would have to be derived from this signal, this would be very complicated to achieve. However if a threshold is created and set at 50% this allows two values to be obtained, this means any signal received above this threshold would be 1 and any signal received below this would be 0.

__Lsb and Msb__
Characters in number systems are read from right to left, the furthest right character being the least significant bit (lsb) and the furthest left character being the most significant bit (msb). Using the place value of where the character is situated within the number, a value can be applied, for example in the decimal number system each place value is increased by a power of ten. In the binary number system each place value increases by the power of 2 as shown in the diagram below.



Therefore to show the decimal numbers 1 to 10 in binary it would look like this using the above place values.

__Octal and Hexadecimal__
There are two other number systems that are used in conjunction with binary; they are called octal and hexadecimal. If a programmer was writing or reading code they would use octal and hexadecimal as a shorthand way of representing binary numbers, because binary numbers can be long, confusing and difficult to read. Octal is base 8, uses the characters 0 to 7 and when using it, binary values are interpreted in groups of three. Hexadecimal is base 16, uses the characters 0 to 9 and A to F and when using it, binary values are interpreted in groups of four. It is important to state that computer systems can only understand binary. Octal and hexadecimal are used because it is easier to convert binary to and from octal and hexadecimal than decimal. The following table shows all four number systems together, decimal, octal, hexadecimal and binary. The yellow highlighted sections show the octal grouping.

Back to the top

__Subtask 1.2__
Subtask 1.2 describes how analogue data can be converted and stored in a computer system.

__Analogue Signal__
An analogue signal is a continuous signal that fluctuates in frequency or amplitude over time, where all values are allowed. Analogue signals can be expressed pneumatically, hydraulically, mechanical or electrically. In the case of computer systems analogue refers to electrical signals that respond to pressure, light, sound or heat.

__Digital Signal__
A digital signal is the opposite of analogue. The signal is not continuous, the signal value either on or off. These values can then be represented as binary.

__ADC and DAC__
A computer cannot process analogue information, therefore to store analogue information in a computer system it must be converted into a digital signal using first a device called a Transducer and then a device called an Analogue-to-Digital Converter or ADC. A Transducer is any device that converts one form of energy into another e.g. a microphone. A microphone converts sound waves into vibrations that are then converted into an electrical signal. This electrical signal is an analogue current that is then converted into a digital signal using a device called an Analogue-to-Digital Converter (ADC), an example of an ADC is a soundcard. The digital signal can be represented as a binary value of 1 or 0. The binary signal can then be stored in computer systems. To access the stored binary data the process is reversed and a device called a Digital-to-Analogue Converter (DAC) which converts the binary back into current then using a Transducer is converted back into vibrations and then sound waves an example here would be a speaker.

__Sampling__
For a DAC to be able to change the analogue signal in to a digital signal the continuous analogue wave form sent from the Transducer must be sampled at different fixed intervals or points in time (see below), it is then converted into a discrete-time signal. A discrete-time signal is the succession or series of sampled signal values that describes separate and fixed points in time, the sample is the point in time that the value was taken.

__Quantizing__
It would be impossible to measure the sampled time values exactly as an infinite number of digits (or bits) would be needed. Therefore the measured time is set to the approximate digit (or bit) in a fixed number of digits (or bits). This process is called quantizing; the resulting data is encoded (converted) into a digital signal. This encoded digital signal is used in computer systems. To convert the signal back into analogue the process is reversed, this is call decoding and is performed by a DAC. So in summary, to convert an analogue signal into a digital signal it is sampled, converted into a discrete-time signal, which is then quantized and encoded into a digital signal.

Back to the top

__Subtask 1.3__
Subtask 1.3 relates to data stored in memory locations in an 8-bit memory store. The task is to convert each of the following binary numbers into decimal and hexadecimal. a) 01010111 b) 11101010 c) 10111100 d) 10101101

__Decimal Answers__
To convert each number to a decimal value all 8 binary digits are used to calculate the value from right to left, each place value increasing to the power of two. The easiest way to work this out is to use the following table, place the binary number in the second row (as in the example) and add the values together in the first row with a number 1 below it.

Therefore the decimal answers are: a) 87 b) 234 c) 188 d) 173

__Hexadecimal Answers__
To work out hexadecimal values the same binary numbers must be split into groups of four e.g. 0101, 0111. The hexadecimal value is then applied to each group of four separately. As mentioned in Subtask 1.1 hexadecimal values are 0 to 9 and A to F. The easiest way to work out the answer is to use the table in Subtask 1.1. Therefore the hexadecimal answers are: a) 5, 7 b) E, A c) B, C d) A, D = =

Back to the top

__Subtask 1.4__
Subtask 1.4 deals with converting hexadecimal into binary and performing calculation operations. 2’s compliment arithmetic is to be used where appropriate. To perform calculations with Hexadecimal the values first need to be converted into Binary.

a) B4+FC

To add Binary numbers together the Minuend needs to be added to the Subtrahend using the rules: Using this rule the calculation would look like this: This Binary answer needs to be converted back into Hexadecimal. To do this the numbers need to be in groups of four, read from right to left. This would result in the following groups: As can be seen above extra 0’s have been added (highlighted in yellow) to make up the final group of four. This converted then gives the final Hexadecimal answer: **1B0.**

Back to the top b) CC-7A

With Binary subtractions the ‘Twos compliment’ method has to be used. To do this, first convert the Hexadecimal to binary: The ‘Twos compliment’ method is then applied to the sum. This involves reversing the Subtrahend; this is called ‘Ones Compliment’. To this altered number the value of 1 is added, this is called ‘Twos Compliment’ (highlighted below). This ‘Twos compliment’ Subtrahend is then added to the ‘Minuend’ using the addition method. In Binary subtraction (MSB) most significant bit in the answer (circled) is ignored. However this can be used to calculate whether the rest of the answer is positive or negative. If the MSB is 1 the answer is positive, if the MSB is 0 the answer is negative. his Binary answer needs to be converted back into Hexadecimal. To do this the numbers need to be in groups of four, read from right to left. This would result in the following groups. This converted then gives the final Hexadecimal answer: **52.**

Back to the top c) 29x06

The multiplication of Binary is not dissimilar to Decimal long multiplication. Each of the digits is multiplied right to left in turn and the values are then added together. This Binary answer needs to be converted back into Hexadecimal. To do this the numbers need to be in groups of four, read from right to left. This would result in the following groups: As can be seen above extra 0’s have been added (highlighted in yellow) to make up the final group of four. This converted then gives the final hexadecimal answer: **0F6.**

Back to the top d) 0F÷05

For the division of Binary numbers, convert the Hexadecimal to binary; next convert the binary to decimal. Work the answer out in decimal, and then convert the answer back to Hexadecimal. Therefore for this example the Binary version of the number 3 is: This converted then gives the final //Hexadecimal// answer: **3.**

Back to the top e) 73+25 Binary to Hexadecimal, Groups of four: Translates in ‘Hex’ to: **98**.

Back to the top f) 56-33

Using the ‘Twos compliment’ method. Convert to Binary. Use 'Twos Compliment'. 'Twos Compliment'. This ‘Twos compliment’ Subtrahend is then added to the ‘Minuend’ using the addition method. Binary to Hexadecimal, Groups of four (with a positive MSB): Translates in ‘Hex’ to **23**.

Back to the top g) 17x03 Binary to Hexadecimal, Groups of four: Translates in ‘Hex’ to: **045.**

Back to the top h) 06÷02 Therefore for this example the Binary version of the number 3 is: This converted then gives the final Hexadecimal answer: **3**.

Back to the top =__Task 2__=

__Subtask 2.1__
Subtask 2.1 deals with the operation of six basic logic gates needs to be described with the aid of truth tables, each will include the logic symbol and logic expression.

__Boolean Logic__
In the mid 18th century a mathematician named George Boole created an algebraic system of logic that has become the foundation of all contemporary digital electronics. This group of logical processes is named after him and known as Boolean Logic. The following six logic gates are used in modern computer systems and use Boolean Logic.

__Logic Gates__
The names of logic gates is decided by their function and are written in capital letters, we will be looking at the gates AND, NOT, OR, NOR, NAND and EXOR. With the exception of the NOT gate which only has one input, logic gates can have two or more inputs, the amount of inputs each gate can allow will be stated in each example. All the gates have one output.

__True and False__
When talking about logic gates we are talking about signals travelling a path. There are a number of ways to represent a positive signal and a negative signal e.g. on, off or 1, 0, however in the following examples we will be using the phrase ‘true’ if the signal is positive and ‘false’ if the signal is negative.

__Truth Tables__
When using Boolean algebra in conjunction with logic gates we will be using truth tables, these are a mathematical tables that show all available truth values that it is possible to find from the inputs. In the truth tables inputs will be represented as A and B and outputs will be represented as Q.

__How to work out combinations of truth values__
With logic gates it is possible to worked out the number of combinations of truth values there will be by working out the number of input to the power of two, e.g. two inputs would be 22, which is 2x2, so this would give four combinations. Three inputs would be 32, which is 2x2x2, so this would give eight combinations and so on.

__Terms and Expressions__
To simplify truth tables terms and expressions can be used. These work as follows. If an output in a truth table is true (shows the number 1) the full truth value can be shown as a term or Boolean product expression as seen below. The apostrophe (‘) represents an abbreviation for 0 or false and the (.) represents AND. These Boolean product expressions can be joined together to form one Boolean expression as follows: The (+) represents an abbreviation for OR. The Boolean expression is a simplified way of expressing the truth table and a truth table can be worked out from the Boolean expression.
 * A’.B.C + A.B’.C + A.B.C’ **

Back to the top

__AND Gate__
AND gates can have two or more inputs. The symbol for the AND gate is:

If A AND B are true, then Q is true. Or A AND B = **Q**. This can be represented in a truth table as follows: The Boolean expression for the AND gate is therefore: **A.B**

Back to the top

__OR Gate__
OR gates can have two or moe inputs.The symbol for the OR gate is: If A OR B are true, then Q is true. Or A + B = Q. If any input is true the output is true. Shown in a truth table below: The Boolean expression for the OR gate is therefore: **A’.B+A.B’+A.B**

Back to the top

__NOT Gate__
NOT gates can only have one input. The symbol for the NOT gate is: If A is true then Q is NOT true. If A is NOT true then Q is true. The NOT gate is also called an inverter because it changes the input to the opposite value. So NOT A = **Q**. Shown as a truth table below: The Boolean expression is therefore **A’**. The circle shown on the NOT gate can be attached to other gates to show that the output signal needs to be inverted with a NOT gate.

Back to the top

__NAND Gate__
NAND gates can have two or more inputs. The symbol for the NAND gate is: A NAND gate is an AND gate with the output inverted. Therefore, if A or B are not true the out put is true. So NOT (A AND B) = **Q**. The Boolean expression for the NAND gate is therefore **A’.B’+A’.B+A.B’**

Back to the top

__**NOR Gate**__
NOR gates can have two or more inputs. The symbol for the NOR gate is: A NOR gate is an inverted OR gate. Therefore if A and B are NOT true then Q is true. This can be shown as NOT (A OR B) = **Q**. The Boolean expression for the NOR gate is therefore **A’.B’**

Back to the top

__XOR Gate__
XOR gates can only have two inputs. The symbol for the XOR gate is:

The X in XOR is an abbreviation for ‘Exclusive OR’. If A OR B are true, then Q is true but not if both are true. This can be shown as (A AND NOT B) OR (B AND NOT A) = **Q**. The Boolean expression is therefore: **A’.B+A.B’**

Back to the top

__A-Stable__
A circuit that continually switches from one state to another, on, off, on, off, is known as an Astable circuit. This square wave oscillation will continue as long as there is a power source. This is useful for providing a clock pulse in internal free running clocks because it is constant while powered. This circuit could also be used for flashing lamps, LED’s, Buzzers, Alarms, or even for sending Morse code in amateur radio.

__An Astable Square Wave__


Using the program Multimedia Logic provided by the tutor, a simple Astable circuit can be shown as follows:

__A Simple Astable Circuit__
An example of a well known and useful Astable integrated circuit is the 555 Astable Circuit. This is a circuit that contains a 555 Timer IC, a pre-built integrated circuit, first released in the 1970’s. They are popular because they are dependable, fairly inexpensive and are a stable technology. When used in an Astable circuit they oscillate and the frequency and cycle can be adjusted with two resistors and a capacitor.

__Bi-Stable or Flip Flop__
When a circuit is said to have two stable states it is known as Bistable. When it is triggered the circuit ‘flips’ and ‘flops’ from one state to another and stays in that state until it is triggered again. This can be used to ‘latch’ the circuit on and off. This type of circuit is used as an essential part of memory devices.

__Bi-Stable or Flip Flop Square Wave__
Back to the top

__Multimedia Logic__
Using the program [|Multimedia Logic] provided by the tutor, a simple Bi-Stable circuit can be shown as follows:

__A Simple Bi-Stable Circuit__
When the ‘Set’ button is triggered the light and buzzer switch on. When the ‘Re-Set’ button is pressed the light and buzzer switch off.

The 555 Timer chip can be used in a 555 Bi-Stable Circuit to act as a flip flop as follows:

__Bi-Stable 555 Circuit__


Back to the top

__How to design and simplify a circuit__
To design a prototype process control system, a number of stages have to be completed to reach the final design, these are:
 * **Step One:** Design a truth table for the number of inputs being used.
 * **Step Two:** Apply the outputs needed for the circuit.
 * **Step Three:** Work out the terms of the truth table.
 * **Step Four:** Obtain the expression from the terms.
 * **Step Five:** Design the logic circuit and test if it performs to the required specification.
 * **Step Six:** Create a Karnaugh Map using the expression.
 * **Step Seven:** Using the Karnaugh map simplify the Logic Circuit.

__Design Specifications__
The specification we have been given is designed to check a four-bit binary number with the hexadecimal range, it consists of:

a) Four inputs (A, B, C, and D) and a single output (X). b) The output will be true (produce logic 1) all odd numbers apart from the letter F (in HEX) which is to be ignored. c) A seven segment display is to be connected to the input bus to show the hexadecimal value. d) Output X needs to be connected to one input of a two input OR gate (Z). e) The second input on the OR gate (Z) needs to be connected to a square wave clock source. f) The output will be represented by a LED and/or buzzer. g) The original circuit must be shown. h) A simplified circuit must be shown.

The circuits once designed will be shown using the program Multimedia logic.

__Steps One to Three__
The following truth table covers steps 1 to 3.

__Step Four__
Therefore step 4 is expression is: **A’.B’.C’.D+A’.B’.C.D+A’.B.C’.D+A’.B.C.D+A.B’.C’.D+A.B’.C.D+A.B.C’.D**

__Step Five__
This is the more complicated circuit designed with the expression from the truth table.

__Step Six__
From the truth table expression a Karnaugh map can be built.

__Step Seven__
The figure in red would normally be a positive, however because we are ignoring the hexadecimal value F this is represented in this map as a zero. a) A.B’.D b) C’.D c) A’.D Therefore using the Karnaugh map the expression is simplified to: **A.B’.D+C’.D+A’.D**

Then using the simplified expression derived from the Karnaugh map a simplified circuit can be built.

Back to the top

__Input Devices__
An input device is a hardware device that transmits information into the CPU. Without an input device, the user would not be able to interact with the CPU. Examples of input devices are the keyboard, mouse, web camera, scanner, microphone, joystick or digital camera.

__Output Devices__
An output device is any hardware device used to transmit to the outside world the outcome of data processed by the CPU. Examples of output devices are the monitor, speakers, headphones or printer.

__Backing store__
Backing store is any device used to store applications, data or the operating system on. Examples are the hard drive, flash drive or DVD.

__The Central Processing Unit (CPU)__
The primary role of any CPU is to perform a complex series of instructions in succession; this sequence is known as a program. These programs are stored in the memory of a computer in the form of numbers.

Once a computer has been switched on it continuously operates the fetch execute cycle:




 * **Fetch** - the next instruction from the computer memory is collected.
 * **Decode** – deciphers this instruction for use.
 * **Execute** – the instruction is acted upon.
 * **Writeback** - the result if the executed instruction is written back into computer memory. This memory could be temporary memory for quick access, while the cycle is in use or permanent memory for longer storage.

Back to the top

__CPU Component Parts__
To be able to operate this cycle the CPU has different component parts within it that perform different functions a graphic representation you can see below:



__A.L.U. (Arithmetic Logic Unit)__
The ALU is the fundamental building block of a CPU and deals with all the mathematical calculations by processing binary signals. It also deals with the logical operations that take place within the processor using logic ‘gates’ (NOT, AND, OR) these gates apply [|‘Boolean logic’] and the results permit different actions. Data to necessary to carry out these mathematical and logical functions are inputs from designated CPU registers and  [|operands].

__Control Unit__
The control unit is circuitry responsible for directing and managing the CPU and therefore the rest of the computer, using electrical signals. Program commands are not carried out by the control unit, instead it tells other parts of the internal system to carry out these commands e.g. when to spin or not to spin.

__Registers__
Registers or Processor registers are a segment of memory inside the CPU used as a temporary store for data the CPU uses, it must copy the data to the registers to work with it and copy it back afterwards as it cannot directly work with the data in the main memory. The number of registers varies between processors and they are numerous. Some general purpose registers are:
 * **Program Counter (PC)** – also known as an instruction pointer or instruction address register. This register is read from and written to by the Control unit to store the memory address or location of the next instruction to be executed. Once this instruction has been carried out the Control Unit increments the Program Counter by 1 to give the address of the next memory address. It works like this because program commands are normally stored in sequential memory locations. However in the case of instructions like Jump, or Branch the sequence is altered. In this case a new value put in the Program Counter as the beginning of a new sequence of instructions stored in the memory. Another example where the sequence is altered is a Subroutine. In this case the memory address value in the Program Counter is copied into the main memory or another register, a new instruction sequence is run. When this is completed the old instruction value is then copied back into the Program Counter and then continued.
 * **Memory Address Register (MAR)** – This register copies and holds the memory address of the next specific memory word from the PC (the next instruction to be executed) while the previous instruction is being carried out. The data is then used to copy the instruction word to the MBR.
 * **Memory Buffer Register (MBR**) – This register acts as a buffer between the outside Data Bus and the internal CPU. The contents of a memory word are transferred in and out of main memory through the MBR. The memory address in the MAR is used to perform a memory read and the data is transported into the MBR. This buffering allows the CPU and the main memory to perform autonomously, therefore stopping differences in operation between the two affecting each other. The MBR is also used to buffer arithmetic data that will be sent to the Accumulator to be processed by the ALU.
 * **‘Current’ Instruction Register (CIR)** – This register is normally found within the Control Unit and its job is to store the instruction that is current being decoded or executed. An instruction held in the MBR is transferred into the CIR to be used.
 * **Accumulator (A)** – Found in the ALU. This register is the holding area for data to be used for arithmetic in the ALU. Numbers are copied to the accumulators by passing through the MBR; they are then used for addition or subtraction. The accumulators are also used to store the results of calculations before being passed back to the MBR to then be stored in the main memory.

__Instruction set__
The instruction set is a permanent list of instructions hardwired into the electronics of the CPU. It is this list of instructions that defines the processor and is the platform on which a program is written.

Back to the top

__System Bus__
This diagram shows the three buses that connect to a CPU:

__Bus__
A bus is a wire pathway, channel or conduit which is used to transfer binary data between the components inside a computer. These channels are fixed into the motherboard. The width of the bus governs the amount of data that can be sent at one time. An 8 bit bus can send 8 bits of information at a time, while a 32 bit bus can send 32 bits of information at a time. The more information a bus can transfer the faster applications can be run.

There are three buses attached to the CPU:

__Data Bus__
The data bus is a bi-directional bus, this means that information travels in both directions on it. As the devices inside the computer are required to be able to share information with each other and the CPU and they do this through the data bus. A large part of the CPU connections are taken up by the data bus.

__Address Bus__
The address bus is a uni-directional bus, this means that information only travels in one direction. Although it speaks to all devices, it carries the address of the device to be used at that particular time and tells that device to work. A large part of the CPU connections are also taken up by the address bus.

__Control Bus__
The control bus is also a uni-directional bus. This bus sends single signals to control actions such as reading and writing and to report the status of various devices. Each individual component may need its own line however the control bus is no way as large as the data bus or address bus.

Back to the top

__The Fetch – Execute Cycle__
Data travelling around the processor can be represented using a simple flow chart as follows: In more detail the fetch – execute cycle can be explained as follows:

__The Fetch Phase__
This is applicable to all instructions.
 * 1) The address location in the PC (Program Counter) is copied into the MAR (Memory Address Register). The MAR now has the location address of the next instruction. A memory read is commenced; the instruction word is then copied from the main memory into the MBR (Memory Buffer Register).
 * 2) The PC now increases by one number and therefore now has the address of the next instruction to be used.
 * 3) The instruction word in the MBR is then copied into the CIR (Current Instruction Register).

__The Execute Phase__
In this phase the action taken is unique to the instruction.
 * 1) The instruction contained in the CIR is decoded to be used.
 * 2) The now decoded instruction in the CIR is then executed.
 * 3) Unless a STOP instruction is decoded the cycle is then repeated.

Back to the top

__How data travels around the CPU__
An example of how the data travels around the CPU can be seen as follows: The PC (Program Counter) shows the memory location of the next instruction (data), D5 (a hexadecimal value). A memory read takes place and the data is placed into the Instruction Register.

The PC (Program Counter) increases by 1 place to show the next memory location, 2001.

Memory location 2001 contains the hexadecimal data 1F; this data is read to MPL (Memory Partition ‘Lower’).

The Program Counter increases by 1 place to show the next memory location, 2002.

Memory location 2002 contains the hexadecimal data 80; this data is read to MPH (Memory Partition ‘Higher’).

The Program Counter increases by 1 place to show the next memory location.

This process continues with data being read to other locations within the CPU.

Back to the top =__Task 3__=

__Subtask 3.1__
Using the SMS program simulator that has been provided by the tutor, the following section shows some low level programming written to give basic addition, subtraction, multiplication and division.

[|SMS32v23]
When using the simulator it is important to explain what will be seen on the screen. The following diagram shows what a written program will look like within the simulator; the ‘Title Text’ is preceded with a semi-colon, which prevents the simulator reading this text as part of the written program. The ‘Program Commands’ appear after this in two columns, the first column is the command, the second any instruction applied to this command. The ‘Descriptive Text’ informs the user in plain text what each line of the ‘Program Commands’ actually does and finally ‘Further Text’ can be added after the program has ended if needed, again preceded by a semi-colon to prevent the simulator reading the text as part of the program. The next diagram shows the top section of the SMS32v23 program. As the program is a simulator of the x86 instruction set, registers are used. These are represented at the top left hand side of the screen in yellow. Within this yellow section the first column is the name of the register, the second column is the binary value currently being used by the register, the third column is the hexadecimal value and the fourth column shows the decimal value.

When writing the program, pressing the ‘Assemble’ button allows the user to see if the program will work. ‘Translates Source Code to Machine Code’ is the message displayed when placing the mouse over the button. When the program works correctly, a green bar appears underneath the buttons with a message of success. The ‘Step’ button allows the user to scroll through each step of the program to see it work. The ‘Show RAM’ button brings up a window that shows what hexadecimal value is being given for the current command.
 * The mathematical programs being written in this section only use the AL and BL registers? **

__Division, JMP, JZ, PUSH and POP__


Back to the top

__Subtask 3.2__
The task is to design and write a low level program to control the SMS Traffic Simulator for a cross road junction. The program must repeat itself for fifteen cycles and then stop with the lights on red. To do this a truth table needs to be designed to work out the cycle on the traffic lights. The instructions for the lights need to be designed without using the two LSB (Least Significant Bits) because they are not connected to the lights (as seen in the picture to the right).

__The Light Truth Table__
Now knowing that we do not use the 2 LSB, the pattern needed for the traffic lights can be applied to a truth table. Remember hexadecimal numbers are read in groups of four. Their values are shown in the table. The following page shows the program text. This can be cut and pasted into the SMS program to see how it runs.

__Traffic Light Simulation Program__
CLO ; Close unwanted windows. MOV AL,0F ; Move 15 to AL (To count number or rotations) Start: DEC AL ; Subtract one from AL. JZ Stop ; Jump to Stop if AL is Zero. PUSH AL ; Save AL onto the stack
 * KIERON EDWARDS
 * SUBTASK 3.2
 * TRAFFIC LIGHT SIMULATION
 * Turn off all the traffic lights.

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

MOV AL,D0 ; Copy 11010000 into the AL register. (Red/Amber - Red) OUT 01 ; Send AL to Port One (The traffic lights).

MOV AL,30 ; Copy 00110000 into the AL register. (Green - Red) OUT 01 ; Send AL to Port One (The traffic lights).

MOV AL,50 ; Copy 01010000 into the AL register. (Amber - Red) OUT 01 ; Send AL to Port One (The traffic lights).

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

MOV AL,98 ; Copy 10011000 into the AL register. (Red - Red/Amber) OUT 01 ; Send AL to Port One (The traffic lights).

MOV AL,84 ; Copy 10000100 into the AL register. (Red - Green) OUT 01 ; Send AL to Port One (The traffic lights).

MOV AL,88 ; Copy 10001000 into the AL register. (Red - Amber) OUT 01 ; Send AL to Port One (The traffic lights).

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

POP AL ; Restore AL from the stack (to check for number of rotations).

JMP Start ; Jump back to start Stop: END ; Program ends. The program text above combines some of the techniques that have been applied to the arithmetic programs in the previous pages. It uses the hexadecimal values obtained from the traffic light truth table to the design the program. And it works.


 * Word Count = 6137 / Written by Kieron Edwards / 14 July 2010**

__Websites__
__[|www.britannica.com]__ __https://mrsturgeon.wikispaces.com/Tech+Support+-+How+Computers+Work__ – Sound Card Picture. __[]__ - Wave Form Picture. [] - Logics [] - Conversion [|www.answers.com] [|www.webopedia.com] [|www.wisegeek.com] [] - logic gates [] - logic gates [] - Boolean Product expressions [] – Astable diagram [] - Astable in amateur radio reference [] - Bistable [] - 555

Back to the top