microprocessor 8085_ program
microprocessor 8085_ program
Statement: Store the data byte 32H into memory location 4000H.
Program 1:
Program 2:
Note:
The result of both programs will be the same. In program 1 direct addressing instruction
is used, whereas in program 2 indirect addressing instructions is used.
LDA 2000H : Get the contents of memory location 2000H into accumulator
MOV B, A : Save the contents into B register
LDA 4000H : Get the contents of memory location 4000Hinto accumulator
STA 2000H : Store the contents of accumulator at address 2000H
MOV A, B : Get the saved contents back into A register
STA 4000H : Store the contents of accumulator at address 4000H
Program 2:
LXI H 2000H : Initialize HL register pair as a pointer to memory location
2000H.
LXI D 4000H : Initialize DE register pair as a pointer to memory location
4000H.
MOV B, M : Get the contents of memory location 2000H into B register.
LDAX D : Get the contents of memory location 4000H into A register.
MOV M, A : Store the contents of A register into memory location
2000H.
MOV A, B : Copy the contents of B register into accumulator.
STAX D : Store the contents of A register into memory location
4000H.
HLT : Terminate program execution.
Note:
In Program 1, direct addressing instructions are used, whereas in Program 2, indirect
addressing instructions are used
1
Statement: Add the contents of memory locations 4000H and 4001H and place the
result in memory location 4002H.
Sample problem
(4000H) = 14H
(4001H) = 89H
Result = 14H + 89H = 9DH
Source program
Statement: Subtract the contents of memory location 4001H from the memory
location 2000H and place the result in memory location 4002H.
Program : Subtract two 8-bit numbers
Sample problem:
(4000H) = 51H
(4001H) = 19H
Result = 51H - 19H = 38H
Source program:
Statement: 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.
Sample problem:
2
(4000H) = 15H
(4001H) = 1CH
(4002H) = B7H
(4003H) = 5AH
Result = 1C15 + 5AB7H = 76CCH
(4004H) = CCH
(4005H) = 76H
Source Program 1:
LHLD 4000H : Get first I6-bit number in HL
XCHG : Save first I6-bit number in DE
LHLD 4002H : Get second I6-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 I6-bit result in memory locations 4004H and 4005H.
HLT : Terminate program execution
Source program 2:
LHLD 4000H : Get first I6-bit number
XCHG : Save first I6-bit number in DE
LHLD 4002H : Get second I6-bit number in HL
DAD D : Add DE and HL
SHLD 4004H : Store I6-bit result in memory locations 4004H and 4005H.
HLT : Terminate program execution
Statement: Add the contents of memory locations 40001H and 4001H and place the
result in the memory locations 4002Hand 4003H.
Sample problem:
(4000H) = 7FH
(400lH) = 89H
Result = 7FH + 89H = lO8H
(4002H) = 08H
(4003H) = 0lH
Source program:
3
INX H :HL Points 4002H
MOV M, A :Store the lower byte of result at 4002H
MVIA, 00 :Initialize higher byte result with 00H
ADC A :Add carry in the high byte result
INX H :HL Points 4003H
MOV M, A :Store the higher byte of result at 4003H
Statement: 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.
Sample problem
(4000H) = 19H
(400IH) = 6AH
(4004H) = I5H (4003H) = 5CH
Result = 6A19H - 5C15H = OE04H
(4004H) = 04H
(4005H) = OEH
Source program:
Statement: Find the l's complement of the number stored at memory location 4400H
and store the complemented number at memory location 4300H.
Sample problem:
(4400H) = 55H
Result = (4300B) = AAB
Source program:
4
Statement: Find the 2's complement of the number stored at memory location
4200H and store the complemented number at memory location 4300H.
Sample problem:
(4200H) = 55H
Result = (4300H) = AAH + 1 = ABH
Source program:
Statement: Pack the two unpacked BCD numbers stored in memory locations
4200H and 4201H and store result in memory location 4300H. Assume the least
significant digit is stored at 4200H.
Sample problem:
(4200H) = 04
(4201H) = 09
Result = (4300H) = 94
Source program
NOTE:
BCD NO.: The numbers "0 to 9" are called BCD (Binary Coded Decimal) numbers.
5
Statement: Two digit BCD number is stored in memory location 4200H. Unpack the
BCD number and store the two digits in memory locations 4300H and 4301H such
that memory location 4300H will have lower BCD digit.
Sample problem
(4200H) = 58
Result = (4300H) = 08 and
(4301H) = 05
Source program
6
Statement: Write a program to shift an eight bit data four bits right. Assume that
data is in register C.
Source program:
MOV A, C
RAR
RAR
RAR
RAR
MOV C, A
HLT
Statement:Write a program to shift a 16 bit data, 1 bit right. Assume that data is in
BC register pair.
Source program:
MOV A, B
RAR
MOV B, A
MOV A, C
RAR
MOV C, A
HLT
7
Statement: Program to shift a 16-bit data 1 bit left. Assume data is in the HL
register pair.
Source program:
Statement: Write a set of instructions to alter the contents of flag register in 8085.