### 8085 program to move blocks of bits from source location to a destination location: ###
2000 MVI C, 05 [C] <- 05
2002 LXI H, 2500 [H-L] <- 2500
2005 LXI D, 2600 [D-E] <- 2600
2008 MOV A, M [A] <- [[H-L]]
2009 STAX D [A] -> [[D-E]]
200A INX H [H-L] <- [H-L] + 1
200B INX D [D-E] <- [D-E] + 1
200C DCR C [C] <- [C] – 1
200D JNZ 2008 Jump if not zero to 2008
2010 HLT Stop
Explanation – Registers A, D, E, H, L, C are used for general purpose:
MOV is used to transfer the data from memory to accumulator (1 Byte)
LXI is used to load register pair immediately using 16-bit address (3 Byte instruction)
MVI is used to move data immediately into any of registers (2 Byte)
STAX is used to store accumulator into register pair indirectly (3 Byte instruction)
DCR is used to decrease register by 1 (1 Byte instruction)
INX is used to increase register pair by 1 (1 Byte instruction)
JNZ is used to jump if not zero to given memory location (3 Byte instruction)
HLT is used to halt the program
### 8085 program to add two 8 bit numbers: ###
2000 LDA 2050 A<-[2050]
2003 MOV H, A H<-A
2004 LDA 2051 A<-[2051]
2007 ADD H A<-A+H
2008 MOV L, A L←A
2009 MVI A 00 A←00
200B ADC A A←A+A+carry
200C MOV H, A H←A
200D SHLD 3050 H→3051, L→3050
2010 HLT
Explanation –
LDA 2050 moves the contents of 2050 memory location to the accumulator.
MOV H, A copies contents of Accumulator to register H to A
LDA 2051 moves the contents of 2051 memory location to the accumulator.
ADD H adds contents of A (Accumulator) and H register (F9). The result is stored in A itself. For all arithmetic instructions A is by default an operand and A stores the result as well
MOV L, A copies contents of A (34) to L
MVI A 00 moves immediate data (i.e., 00) to A
ADC A adds contents of A(00), contents of register specified (i.e A) and carry (1). As ADC is also an arithmetic operation, A is by default an operand and A stores the result as well
MOV H, A copies contents of A (01) to H
SHLD 3050 moves the contents of L register (34) in 3050 memory location and contents of H register (01) in 3051 memory location
HLT stops executing the program and halts any further execution
### 8085 program to multiply two 8 bit numbers: ###
Memory Address Mnemonics Comment
2000 LHLD 2050 H←2051, L←2050
2003 XCHG H↔D, L↔E
2004 MOV C, D C←D
2005 MVI D 00 D←00
2007 LXI H 0000 H←00, L←00
200A DAD D HL←HL+DE
200B DCR C C←C-1
200C JNZ 200A If Zero Flag=0, goto 200A
200F SHLD 3050 H→3051, L→3050
2012 HLT
Explanation – Registers used: A, H, L, C, D, E
LHLD 2050 loads content of 2051 in H and content of 2050 in L
XCHG exchanges contents of H with D and contents of L with E
MOV C, D copies content of D in C
MVI D 00 assigns 00 to D
LXI H 0000 assigns 00 to H and 00 to L
DAD D adds HL and DE and assigns the result to HL
DCR C decrements C by 1
JNZ 200A jumps program counter to 200A if zero flag = 0
SHLD stores value of H at memory location 3051 and L at 3050
HLT stops executing the program and halts any further execution
### 8085 programs to find 2’s complement with carry: ###
2000 LDA 2050 A←2050
2003 CMA A←complement of A
2004 INR A A←A+01
2005 MOV L, A L←A
2006 MVI A 00 A←00
2008 ADC A A←A+A+Carry
2009 MOV H, A H←A
200A SHLD 3050 L→3050, H→3051
200D HLT
Explanation – Registers used: A, H, L
LDA 2050 loads content of 2050 in A
CMA complements the contents of A
INR A increases A by 01
MOV L, A copies contents of A in L
MVI A 00 moves 00 in A
ADC A adds A, A, Carry and assigns it to A
MOV H, A copies contents of A in H
SHLD 3050 stores value of H at memory location 3051 and L at 3050
HLT stops executing the program and halts any further execution
### 8085 program to find square root of a number: ###
MEMORY ADDRESS MNEMONICS COMMENT
2000 MVI D, 01 D <- 01
2002 MVI E, 01 E <- 01
2004 LDA 2050 A <- M[2050]
2007 SUB D A <- A – D
2008 JZ 2011 Jump if ZF = 0 to memory location 2011
200B INR D D <- D + 1
200C INR D D <- D + 1
200D INR E E <- E + 1
200E JMP 2007 Jump to memory location 2007
2011 MOV A, E A <- E
2012 STA 3050 A -> M[3050]
2015 HLT END
Explanation – Registers used A, D, E:
MVI D, 01 – initialize register D with 01
MVI E, 01 – initialize register E with 01
LDA 2050 – loads the content of memory location 2050 in accumulator A
SUB D – subtract value of D from A
JZ 2011 – make jump to memory location 2011 if zero flag is set
INR D – increments value of register D by 1. Since it is used two times, therefore value of D is incremented by 2
INR E – increments value of register E by 1
JMP 2007 – make jump to memory location 2007
MOV A, E – moves the value of register E in accumulator A
STA 3050 – stores value of A in 3050
HLT – stops executing the program and halts any further execution
### 8085 program to count the number of ones in contents of register B : ###
2000 MVI B 75 B ← 75
2002 MVI C 08 C ← 75
2004 MVI D 00 D ← 00
2006 MOV A, B A ← B
2007 RRC Rotate right without carry
2008 JNC 200C Jump if Not Carry
200B INR D D ← D+1
200C DCR C C ← C-1
200D JNZ 2007 Jump if Not Zero
2010 MOV A, D A ← D
2011 STA 3050 A → 3050
2014 HLT Stops execution
Explanation:
MVI B 75 moves 75 decimal numbers into the B register
MVI C 08 moves 08 decimal number into C register, which is taken as counter as the number is of 8 bites
MVI D 00 moves 00 number into d register
MOV A, B moves the contents of B register into A (accumulator) register
RRC rotates the contents of A (which is 75 with binary equivalent 01110101) right
JNC 200C jumps to 200C address and performs the instructions written there if the carry flag is not zero
INR D increases the value of the D register by adding one to its contents
DCR C decreases the value of the C register by subtracting one from its contents
JNZ 2007 jumps to the 2007 address and performs the instructions written there if the zero flags are not zero
MOV A, D moves the contents of the B register into the A register
STA 3050 store the contents of A at 3050 memory location
HLT stops execution
### 8085 program to add numbers in an array: ###
2000 LDA 2050 A <- [2050]
2003 MOV B, A B <- A
2004 LXI H, 2051 H <- 20 and L <- 51
2007 MVI A, 00 A <- 00
2009 MVI C, 00 C <- 00
200B ADD M A <- A+M
200C INR L M <- M+1
200D JNC 2011
2010 INR C C <- C+1
2011 DCR B B <- B-1
2012 JNZ 200B
2015 STA 3050 3050 <- A
2018 MOV A, C A <- C
2019 STA 3051 3051 <- A
201C HLT Terminates the program
Explanation –
LDA 2050: load accumulator with content of location 2050
MOV B, A: copy contents of accumulator to register B
LXI H, 2051: store 20 to H register and 51 to L register
MVI A, 00: store 00 to accumulator
MVI C, 00: store 00 to register C
ADD M: add accumulator with the contents of memory location given in HL register pair
INR L: increase address by 1
JNC 2011: if not carry, jump to location 2011 otherwise to the location given in PC
INR C: increase content of register C by 1
DCR B: decrease content of register B by 1
JNZ 200B: if not zero, jump to location 200B otherwise to the location given in PC
STA 3050: store contents of accumulator to memory location 3050
MOV A, C: copy contents of register C to accumulator
STA 3051: store contents of accumulator to memory location 3051
HLT: terminates the program
### 8085 program to convert binary numbers to gray: ###
2000 STC CY <- 1
2001 CMC CY <- 1's Compliment of CY
2002 LDA 2050 A <- 2050
2005 MOV B,A B <- A
2006 RAR Rotate accumulator right with carry
2007 XRA B A = A XOR B
2008 STA 3050 3050 <- A
200B HLT Stop
Explanation –
STC is used to set carry flag (CY) to 1.
CMC is used to take 1’s compliment of the contents of carry flag (CY).
LDA 2050 is used load the data from address 2050 in A.
MOV B, A is used to move the data of A into B.
RAR is used to rotate the bits of A along with carry flag (CY) to right one time.
XRA B is used to perform XOR operation between the contents of register A and B.
STA 3050 is used to store the contents of A to 3050.
HLT is used end the program.
### 8085 program to perform AND operation in nibbles of 8 bit number: ###
2000 LDA 2050 A <- M[2050]
2003 ANI 0F A <- A (AND) 0F
2005 MOV B, A B <- A
2006 LDA 2050 A <- M[2050]
2009 ANI F0 A <- A (AND) F0
200B RLC Rotate accumulator left by one bit without carry
200C RLC Rotate accumulator left by one bit without carry
200D RLC Rotate accumulator left by one bit without carry
200E RLC Rotate accumulator left by one bit without carry
200F ANA B A <- A (AND) B
2010 STA 3050 M[3050] <- A
2013 HLT END
Explanation – Registers A, B are used for general purpose.
LDA 2050: load the content of memory location 2050 in accumulator A.
ANI 0F: perform AND operation in A and 0F. Store the result in A.
MOV B, A: moves the content of A in register B.
LDA 2050: load the content of memory location 2050 in accumulator A.
ANI F0: perform AND operation in A and F0. Store the result in A.
RLC: rotate the content of A left by one bit without carry. Use this instruction 4 times to reverse the content of A.
ANA B: perform AND operation in A and B. Store the result in A.
STA 3050: store the content of A in memory location 3050.
HLT: stops executing the program and halts any further execution.
### 8085 program to find smallest number between two numbers: ###
2000 LDA [2500] [A]<-[2500]
2003 MOV B, A [B]<-[A]
2004 LDA 2501 [A]<-[2501]
2007 CMP B [A]<-[A]-[B]
2008 JC * [200C] jump carry
200B MOV A, B [A]<-[B]
200C STA [2502] [A]->[2502]
200F HLT STOP
Explanation –
LDA is used to load accumulator (3 Byte instruction).
CMP is used to compare the content of accumulator (1 Byte instruction).
STA is used to store accumulator direct using 16-bit address (3 Byte instruction).
JC jump if carry (3 Byte instruction).
### 8085 program to find 1’s and 2’s complement of 16-bit number: ###
2000 LHLD [3000] [H-L] <- [3000]
2003 MOV A, L [A] <- [L]
2004 CMA [A] <- [A^]
2005 MOV L, A [L] <- [A]
2006 MOV A, H [A] <- [H]
2007 CMA [A] <- [A^]
2008 MOV H, A [H] <- [A]
2009 SHLD [3002] 1’s complement
200C INX H [H-L] <- [H-L] + 1
200D SHLD [3004] 2’s complement
2010 HLT Stop
Explanation –
A is an 8-bit accumulator which is used to load and store the data
LHLD is used to load register pair H-L direct using 16-bit address (3 Byte instruction)
MOV is used to transfer the data from accumulator to register(any) or register(any) to accumulator (1 Byte)
CMA is used to complement content of accumulator (1 Byte instruction)
SHLD is used to store data from register pair H-L into memory direct using 16-bit address (3 Byte instruction)
INX is used to increase H-L register pair by 1 (1 Byte instruction)
HLT is used to halt the program
### 8085 program to exchange content of HL register pair with DE register pair: ###
F000
16, 56
MVI D,56H
Load D with56H
F002
1E, 78
MVI E,78H
Load D with78H
F004
26, CD
MVI H,CDH
Load D with CDH
F006
2E, EF
MVI L,EFH
Load D withEFH
F008
EB
XCHG
Exchange the content of DE and HL
F009
76
HLT
Terminate the program
8085 program to swap two 8 bit numbers using Direct addressing mode:
2000 LDA [3000] [A] <- [3000]
2003 MOV H, A [H] <- [A]
2004 LDA [3001] [A] <- [3001]
2007 MOV D, A [D] <- [A]
2008 XCHG [H-L] [D-E]
2009 HLT Stop
Explanation – Registers A, H, D are used for general purpose.
LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
MOV is used to transfer the data (1 Byte instruction)
XCHG is used to exchange the data of both the register pair (H-L), (D-E) (1 Byte instruction)
HLT is used to halt the program.