8085 Programs

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

8085 Programs

Store the data byte 50H into memory


location 2000H.

• MVI A, 50H ; Store 50H in the accumulator


• STA 2000H ; Copy accumulator contents at
memory location 2000H
• HLT ; Terminate program execution.
Store the data byte 50H into memory
location 2000H.
• MVI A, 50H ; Store 50H in the accumulator
• LXI H, 2000H ; Load HL register pair with
value(data) 2000H
• MOV M, A ; Copy accumulator contents in
memory location pointed by HL register pair
(2000H)
• HLT ; Terminate program execution.
Store the data byte 50H into memory
location 2000H.
• MVI A, 50H ; Store 50H in the accumulator
• LXI B, 2000H ; Load BC register pair with
value(data) 2000H
• STAX B ; Copy the accumulator contents in
memory address indicated by BC pair
• HLT ; Terminate program execution.

• Result= (2000H)=50H
Copy the contents of memory location
1000H to register C.
• LDA 1000H ; Get the contents of memory
location 1000H into accumulator
• MOV C, A ; Copy the accumulator into register
C
• HLT ; Terminate program execution.
• Sample Example:
• (1000H) = 25H
• Result= (C)=25H
Copy the contents of register B to memory
location 1000H.
• MOV A, B ; Copy the accumulator into register
C
• STA 1000H ; Get the contents of memory
location 1000H into accumulator
• HLT ; Terminate program execution.
• Sample Example:
• (B) = 4AH
• Result= (1000H)=4AH
Exchange the contents of memory
locations 2000H and 2001H.
• LDA 2000H ; Get the contents of memory location 2000H into
accumulator
• MOV B, A ; Save the contents into B register
• LDA 2001H ; Get the contents of memory location 2001H into
accumulator
• STA 2000H ; Store the contents of accumulator at address 2000H
• MOV A, B ; Get the saved contents back into A register
• STA 2001H ; Store the contents of accumulator at address 2001H
• HLT ; Terminate program execution.
• Sample Example:
• (2000H) = 55H
• (2001H)= 44H
• Result= (2000H)=44H and (2001H)=55H
Write 8085 Assembly language program to swap two
16-bit number stored at location 8000H – 8001H and
8002H – 8003H using direct addressing mode.
Add the contents of memory locations
4000H and 4001H and place the result in
memory location 4002H.
• LXI H, 4000H ; Load HL with 4000H
• MOV A, M ; Copy the operand from memory (H-L pair) into accumulator
• INX H ; Increment memory address by 1 (HL points 4001H)
• ADD M ; Add accumulator with second operand, result stored in
accumulator
• INX H ; Increment memory address by 1 (HL points 4002H)
• MOV M, A ; Store result at 4002H
• HLT ; Terminate program execution
• Sample Example:
• (4000H) = 23H
• (4001H) = 69H
• Result = 23H + 69H = 8CH
Add the contents of memory locations 2000H
and 2001H and place the result in the memory
locations 2002Hand 2003H.
• LXI H, 2000H ; Load HL with 2000H
• MOV A, M ; Copy the operand from memory (H-L pair) into accumulator
• INX H ; Increment memory address by 1 (HL points 2001H)
• ADD M ; Add accumulator with second operand, result stored in accumulator
• INX H ; HL Points 2002H
• MOV M, A ; Store the lower byte of result at 2002H
• MVI A, 00 ; Initialize higher byte result with 00H
• ADC A ; Add carry in the high byte result
• INX H ; HL Points 2003H
• MOV M, A ; Store the higher byte of result at 2003H
• HLT ; Terminate program execution
• Sample Example:
• (2000H) = 98H
• (2001H) = F7H
• Result = 98H + F7H = 018FH
• (2002H) = 8FH
Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit
number in memory locations 4002H and 4003H. The most significant eight
bits of the two numbers to be added are in memory locations 4001H and
4003H.
Store the result in memory locations 4004H and 4005H with the most
significant byte in memory location 4005H.

• LHLD 4000H ; Get first 16-bit number in H-L register pair


• XCHG ; Save first 16-bit number in D-E register pair
• LHLD 4002H ; Get second 16-bit number in HL
• MOV A, E ; Get lower byte of the first number
• ADD L ; Add lower byte of the second number
• MOV L, A ; Store result in L register
• MOV A, D ; Get higher byte of the first number
• ADC H ; Add higher byte of the second number with CARRY
• MOV H, A ; Store result in H register
• SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
• HLT ; Terminate program execution
Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit
number in memory locations 4002H and 4003H. The most significant eight
bits of the two numbers to be added are in memory locations 4001H and
4003H.
Store the result in memory locations 4004H and 4005H with the most
significant byte in memory location 4005H.

• LHLD 4000H ; Get first 16-bit number in H-L register pair


• XCHG ; Copy first 16-bit number in DE register pair
• LHLD 4002H ; Get second 16-bit number in HL
• DAD D ; Add DE and HL
• SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
• HLT ; Terminate program execution
• Sample Example:
• (4000H) = 20H
• (4001H) = 3AH
• (4002H) = 14H
• (4003H) = 2BH
• Result = 203A + 142BH = 3465H
• (4004H) = 34H
• (4005H) = 65H
Subtract the contents of memory location 1001H from
the memory location 1000H and place the result in
memory location 1002H.
• LXI H, 1000H ; Load HL with 4000H
• MOV A, M ; Copy the operand from memory (H-L pair) into
accumulator
• INX H ; HL points 1001H
• SUB M ; Subtract second operand from accumulator and store
result in accumulator
• INX H ; HL points 1002H
• MOV M, A ; Store result at 1002H.
• HLT ; Terminate program execution
• Sample Example:
• (1000H) = 34H
• (1001H) = 23H
• Result = 34H – 23H = 11H
Subtract the 16-bit number in memory locations 4002H and 4003H from the
16-bit number in memory locations 4000H and 4001H. The most significant
eight bits of the two numbers are in memory locations 4001H and 4003H.
Store the result in memory locations 4004H and 4005H with the most
significant byte in memory location 4005H.
• LHLD 4000H ; Get first 16-bit number in HL
• XCHG ; Save first 16-bit number in DE
• LHLD 4002H ; Get second 16-bit number in HL
• MOV A, E ; Get lower byte of the first number
• SUB L ; Subtract lower byte of the second number
• MOV L, A ; Store the result in L register
• MOV A, D ; Get higher byte of the first number
• SBB H ; Subtract higher byte of second number with borrow
• MOV H, A ; Store 16-bit result in memory locations 4004H and 4005H.
• SHLD 4004H ; Store 16-bit result in memory locations 4004H and 4005H.
• HLT ; Terminate program execution.
• Sample Example:
• (4000H) = 20H
• (4001H) = 3AH
• (4002H) = 14H
• (4003H) = 2BH
• Result = 203AH – 142BH = 0C0FH
• (4004H) = 0CH
Write a microprocessor 8085 program to arrange an array of
data in ascending order. The length of the block is in memory
location 4200H and the block itself starts from memory
location 4201H.
Arrange the numbers in ascending order and store them at
memory location from 4201H. Assume that the numbers in the
block are all 8-bit unsigned binary numbers.

• Algorithm:
• Initialize HL pair as memory pointer.
• Get the count at 4200 into C – register.
• Copy it in D – register (for bubble sort (N-1) times required).
• Get the first value in Accumulator.
• Compare it with the value at next location.
• If they are out of order, exchange the contents of Accumulator and Memory.
• Decrement D –register content by 1.
• Repeat steps 5 and 7 till the value in D- register become zero.
• Decrement contents of C –register by 1.
• Repeat steps 3 to 9 till the value in C – register becomes zero.
• Program: • JNZ LOOP ; jump to loop if not equal to zero.
• LXI H, 4200H ; Set pointer for array. • DCR C ; decrement counter.
• MOV C, M ; Load the count value. • JNZ REPEAT ; jump to repeat if not equal to
• DCR C ; Decrement counter. zero.
• REPEAT: MOV D, C • HLT ; Terminate Program.
• LXI H, 4201H ; Set the memory pointer for • Sample Example:
data. • Input:
• LOOP: MOV A, M ; Move the number into • 4200 05 (Array Size)
accumulator. • 4201 45
• INX H ; Increment memory pointer. • 4202 DE
• CMP M ; Compare memory and accumulator. • 4203 17
• JC SKIP ; jump to skip if carry generated. • 4204 20
• MOV B, M ; copy content of memory location • 4205 50
to B – Register. • Output:
• MOV M, A ; copy content of Accumulator to • 4200 05(Array Size)
memory location.
• 4201 17
• DCX H ; Decrement content of HL pair of
• 4202 20
registers.
• 4203 45
• MOV M, B ; copy content of B – Register to
memory location. • 4204 50
• INX H ; Increment content of HL pair of • 4205 DE
registers.
• SKIP: DCR D ; Decrement content of Register –
D.
Write a microprocessor 8085 program to arrange an array of
data in descending order. The length of the block is in memory
location 4200H and the block itself starts from memory
location 4201H.
Arrange the numbers in descending order and store them at
memory location from 4201H. Assume that the numbers in the
block are all 8-bit unsigned binary numbers.
• Algorithm:
• Initialize HL pair as memory pointer
• Get the count at 4200 into C – register
• Copy it in D – register (for bubble sort (N-1) times required)
• Get the first value in accumulator.
• Compare it with the value at next location.
• If they are out of order, exchange the contents of accumulator and Memory.
• Decrement D –register content by 1.
• Repeat steps 5 and 7 till the value in D- register become zero.
• Decrement C –register content by 1.
• Repeat steps 3 to 9 till the value in C – register becomes zero.
• Program: • HLT
• LXI H, 4200H • Sample Example:
• MOV C, M • Input:
• DCR C • 4200 05 (Array Size)
• REPEAT: MOV D, C • 4201 45
• LXI H, 2201H LOOP: MOV A, M • 4202 DE
• INX H • 4203 17
• CMP M • 4204 20
• JNC SKIP • 4205 50
• MOV B, M • Output:
• MOV M, A • 4200 05(Array Size)
• DCX H • 4201 DE
• MOV M, B • 4202 50
• INX H • 4203 45
• SKIP: DCR D • 4204 20
• JNZ LOOP • 4205 17
• DCR C
• JNZ REPEAT
Find the smallest number in a block of data. The length of the
block is in memory location 2200H and the block itself starts
from memory location 2201H.
Store the smallest number in memory location 2300H. Assume
that the numbers in the block are all 8-bit unsigned binary
numbers.
• Algorithm:
• Load the address of the first element of the array in HL pair
• Move the count to B – register.
• Increment the pointer.
• Get the first data in Accumulator.
• Decrement the count.
• Increment the pointer.
• Compare the content of memory addressed by HL pair with that of Accumulator.
• If carry = 1, go to step 10 or if Carry = 0 go to step 9.
• Move the content of memory addressed by HL to Accumulator.
• Decrement the count.
• Check for Zero of the If ZF = 0, go to step 6, or if ZF = 1 go to next step.
• Store the smallest data in memory.
• Terminate the program.
• Program: smallest
• LXI H,2200H ; Initialize the • AHEAD: DCR B ; Decrement the
memory pointer counter
• MOV B, M ; Copy contents of • JNZ LOOP ; Repeat comparisons
memory to register B till count = 0
• INX H ; Set pointer for array Load • STA 2300H ; Store the largest
the Count value at 2300
• MOV A, M ; Set 1st element as • HLT ; Terminate the program
smallest number • Sample Example:
• DCR B ; Decrement the count • Input:
• LOOP:INX H ; Get the next • (2200H) = 04
number • (2201H) = 34H
• CMP M ; If A- reg < M go to • (2202H) = A9H
AHEAD
• (2203H) = 78H
• JC AHEAD ; Jump to ahead if
• (2204H) = 56H
Carry=1
• Result = (2300H) = 34H
• MOV A, M ; Set the new value as
Find the largest number in a block of data. The length of the block is in memory
location 2200H and the block itself starts from memory location 2201H.
Store the largest number in memory location 2300H. Assume that the numbers in
the block are all 8-bit unsigned binary numbers.

• LDA 2200H • STA 2300H ; Store maximum


• MOV C, A ; Initialize counter. number.
• XRA A ; Maximum = Minimum • HLT ; Terminate program
possible value = 0. execution.
• LXI H, 2201H ; Initialize pointer. • Sample Example:
• BACK: CMP M ; Is number> • (2200H) = 04
maximum. • (2201H) = 34H
• JNC SKIP ; Yes, replace • (2202H) = A9H
maximum. • (2203H) = 78H
• MOV A, M • (2204H) = 56H
• SKIP: INX H • Result = (2300H) = A9H.
• DCR C
• JNZ BACK
Pack the two unpacked BCD numbers stored in memory
locations 2000H and 2001H and store the result in memory
location 2002H. The least significant digit is stored at 2000H.

• Example:
• (2000H) = 04H
• (2001H) = 09H
• Result = (2002H) = 94H
• Program:
• LDA 2001H ; Obtain the most significant BCD digit
• RLC ; Rotate left
• RLC ; Rotate left
• RLC ; Rotate left
• RLC ; Rotate left
• ANI F0H ; Make least significant BCD digit zero
• MOV C, A ; Move the contents of accumulator into C register
• LDA 2000H ; Obtain the least significant BCD digit
• ADD C ; Add lower BCD digit
• STA 2002H ; Store the result in 2002H
• HLT ; Terminate program execution
8085 program to Unpack the BCD number and
store the two digits in memory locations

• LDA 0700 – A 24 bits (3 bytes) command which will load content of memory
location 0700 in register A i.e. Accumulator.
• ANI 0F – It stands for “AND Immediate with Accumulator”. It will perform AND
operation of operand with content of Accumulator. In this case 91 AND 0F.
• STA 0701 – A 24 bits command which will store data of accumulator in
memory location 0701.
• ANI F0 – It stands for “AND Immediate with Accumulator”. It will perform AND
operation of operand with content of Accumulator. In this case 91 AND F0.
• RRC – It stands for “Rotate Right Accumulator”. it will rotate the Accumulator
current content to the right by 1-bit position. LSB bit will be shifted in MSB
and Carry Flag.
• STA 0702 – A 24 bits command which will store data of accumulator in
memory location 0702.
• HTL – It means Halt the microprocessor.

You might also like