Source Program:: 2. Traffic Light Control
Source Program:: 2. Traffic Light Control
Write a program to count number of l's in the contents of D register and store the count
in the B register.
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
Source program :
· MVI B, 00H
· MVI C, 08H
· MOV A, D
· BACK: RAR
· JNC SKIP
· INR B
· SKIP: DCR C
· JNZ BACK
· HLT
Fig. shows the interfacing diagram to control 12 electric bulbs. Port A is used to control
lights on N-S road and Port B is used to control lights on W-E road. Actual pin connections
are listed in Table 1 below.
The electric bulbs are controlled by relays. The 8255 pins are used to control relay on-off
action with the help of relay driver circuits. The driver circuit includes 12 transistors to
drive 12 relays. Fig. also shows the interfacing of 8255 to the system.
INTERFACING DIAGRAM
SOFTWARE FOR TRAFFIC LIGHT CONTROL
Source Program 1:
· MVI A, 80H : Initialize 8255, port A and port B
· OUT 83H (CR) : in output mode
· START: MVI A, 09H
· OUT 80H (PA) : Send data on PA to glow R1 and R2
· MVI A, 24H
· OUT 81H (PB) : Send data on PB to glow G3 and G4
· MVI C, 28H : Load multiplier count (40ıο) for delay
· CALL DELAY : Call delay subroutine
· MVI A, 12H
· OUT (81H) PA : Send data on Port A to glow Y1 and Y2
· OUT (81H) PB : Send data on port B to glow Y3 and Y4
· MVI C, 0AH : Load multiplier count (10ıο) for delay
· CALL: DELAY : Call delay subroutine
· MVI A, 24H
· OUT (80H) PA : Send data on port A to glow G1 and G2
· MVI A, 09H
· OUT (81H) PB : Send data on port B to glow R3 and R4
· MVI C, 28H : Load multiplier count (40ıο) for delay
· CALL DELAY : Call delay subroutine
· MVI A, 12H
· OUT PA : Send data on port A to glow Y1 and Y2
· OUT PB : Send data on port B to glow Y3 and Y4
· MVI C, 0AH : Load multiplier count (10ıο) for delay
· CALL DELAY : Call delay subroutine
· JMP START
Delay Subroutine:
· DELAY: LXI D, Count : Load count to give 0.5 sec delay
· BACK: DCX D : Decrement counter
· MOV A, D
· ORA E : Check whether count is 0
· JNZ BACK : If not zero, repeat
· DCR C : Check if multiplier zero, otherwise repeat
· JNZ DELAY
RET : Return to main program
Separate even numbers from given numbers
Statement: Write an assembly language program to separate even numbers from the
given list of 50 numbers and store them in the another list starting from 2300H. Assume
starting address of 50 number list is 2200H.
Source program :
· LXI H, 2200H : Initialize memory pointer l
· LXI D, 2300H : Initialize memory pointer2
· MVI C, 32H : Initialize counter
· BACK:MOV A, M : Get the number
· ANI 0lH : Check for even number
· JNZ SKIP : If ODD, don't store
· MOV A, M : Get the number
· STAX D : Store the number in result list
· INX D : Increment pointer 2
· SKIP: INX H : Increment pointer l
· DCR C : Decrement counter
· HLT : Stop
Subroutine Program:
· DIV: MVI D, 00H : Clear D-reg for Quotient
· NEXT:SUB C : Subtract the divisor from dividend
· INR D : Increment the quotient
· CMP C : Repeat subtraction until the
· JNC NEXT : divisor is less than dividend
· RET : Return to main program
Note: The square root can be taken by an iterative technique. First, an initial value is
assumed. Here, the initial value of square root is taken as half the value of given number.
The new value of square root is computed by using an expression XNEW = (X + Y/X)/2
where, X is the initial value of square root and Y is the given number. Then, XNEW is
compared with initial value. If they are not equal then the above process is repeated until X
is equal to XNEW after taking XNEW as initial value. (i.e., X ←XNEW)
Source program:
LDA 4200H : Get the number
CMA : Complement the number
ADI, 01 H : Add one in the number
STA 4300H : Store the result
HLT : Terminate program execution
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
Source program :
· MVI B, 00H
· MVI C, 08H
· MOV A, D
· BACK: RAR
· JNC SKIP
· INR B
· SKIP: DCR C
· JNZ BACK
· HLT
Source program :
· LXI H, 6000H : Initialize memory pointer
· MVI C, 00H : Initialize number counter
· MVI B, 00H : Initialize negative number counter
· MVI E, 00H : Initialize zero number counter
· BEGIN:MOV A, M : Get the number
· CPI 00H : If number = 0
· JZ ZERONUM : Goto zeronum
· ANI 80H : If MSB of number = 1i.e. if
· JNZ NEGNUM number is negative goto NEGNUM
· INR D : otherwise increment positive number counter
· JMP LAST
· ZERONUM:INR E : Increment zero number counter
· JMP LAST
· NEGNUM:INR B : Increment negative number counter
· LAST:INX H : Increment memory pointer
· INR C : Increment number counter
· MOV A, C
· CPI 32H : If number counter = 5010 then
· JNZ BEGIN : Store otherwise check next number
· LXI H, 7000 : Initialize memory pointer.
· MOV M, B : Store negative number.
· INX H
· MOV M, E : Store zero number.
· INX H
· MOV M, D : Store positive number.
· HLT : Terminate execution
Subroutine Program:
· FACTO:LXI H, 0000H
· MOV B, C ; Load counter
· BACK: DAD D
· DCR B
· JNZ BACK ; Multiply by successive addition
· XCHG ; Store result in DE
· DCR C ; Decrement counter
· CNZ FACTO ; Call subroutine FACTO
· RET ; Return to main program
Note: In this experiment the number is converted to its equivalent decimal number using
the following logic. First count the number of hundreds, the number of tens & units
present in that hex number. Then add up to get the equivalent decimal number.
Converting A9 we get:
A9 /64=45 Hundreds = 01
Since 64(100 decimal) cannot be subtracted from 45 no. of hundreds = 01. Now count tens
45/0A=3B Tens = 01 Now from 09, 0A cannot be subtracted. Hence tens = 06 the decimal
equivalent of A9 is 169.
LINK : http://www.8085projects.info/page/free-programs-for-8085-microprocessor.aspx