8085 Microprocessor Architecture and Programming-1
8085 Microprocessor Architecture and Programming-1
Anil Swarnkar
Assistant Professor
Electrical Engineering Department.,
MNIT, Jaipur
0000 0101 5 5
1111 1011 -5 251
1111 1111 -1 255
1110 1100 -20 236
1100 1010 -54 202
0011 0110 54 54
Other Flags
Zero flag (Z): If the result of any arithmetical or logical operation in the
accumulator is zero; i.e. all the bits of accumulator (with some exceptions) are
zero; the Zero flag (Z) is set (changed to 1), otherwise reset (changed to 0).
Parity flag (P): If after any arithmetical or logical operation number of 1’s in
the accumulator are even, Parity flag (P) is set (1), otherwise reset (0).
Carry flag (CY): The size of the accumulator is of 8-bits, if after any
arithmetical or logical operation 9th bit is generated, i.e. there is carry beyond
D7 bit of accumulator, Carry flag (CY) is set (1), otherwise reset (0).
Program Counter (PC)
It is a 16-bit register. It is a memory pointer. It stores
the memory address of the next byte of the program is
to be executed
Stack Pointer (SP)
S0
S1
Higher Order Address Bus
Pins AD0-AD7 are used for multiplexed address/data bus. This bus
is bidirectional (Input/output) and serves two purposes. Initially,
the bus is used as lower order address bus, later it is used as data
bus. Means these lines are time-shared and called multiplexed bus.
Separating lower order address bus (A0-A7) and data bus (D0-D7)
using a latch is known as demultiplexing address/data bus.
Demultiplexing is explained later in this chapter.
Control Signals
There are two control signals (RD, WR) and one special signal (ALE) in
this category. All these signals are output signals.
RD (Read signal) – It is an active low control signal. It goes low when read
operation (i.e. reading from memory/input port) takes place.
MOV B, C
Format 2: MOV M, R
From any register to memory.
Memory address is specified by the contents of HL pair,
i.e. [HL] ← R
MOV M, D
Format 3: MOV R, M
From memory to any register, i.e., R ← [HL]
MOV B, M
MVI (Move Immediate)
instruction
This instruction is used to copy 8-bit data specified in the
instruction is directly into the register (R) or Memory
location specified by HL pair.
Format 1: MVI R, 8-bit data
Format 2: MVI M, 8-bit data
LXI (Load Register-pair
Immediate) instruction
This instruction is used to copy 16-bit data specified in the
instruction is directly into the register pair (Rp).
Format: LXI Rp, 16-bit data
Other Data Copy Instructions
LDAX (Load Accumulator Indirect)
LDAX Rp
LDAX B
STAX (Store Accumulator Indirect)
STAX Rp
STAX D
LDA (Load Accumulator Direct) STA (Store Accumulator Direct)
LDA 16-bit address STA 16-bit address
LDA 2060H
STA 3020H
Other Data Copy Instructions
• LHLD (Load HL pair Direct) instruction
– LHLD 16-bit address
– This instruction is used to load HL register pair by data
stored at memory address specified in the instruction and the
next address.
– e.g., LHLD 3010H
• SHLD (Store HL pair Direct) instruction
– SHLD 16-bit address
– This instruction is used to store the contents of HL register
pair to memory address specified in the instruction and the
next address.
– e.g., SHLD 3050H
XCHG (Exchange) instruction
XCHG
HL ↔ DE
INPUT/OUTPUT OPERATIONS
IN (Input) instruction
IN 8-bit port address
This instruction is used to accept data byte from the input port,
whose address specified in the instruction. 8-bit data accepted from
the input port is loaded into the accumulator (A).
A ← [Input port address]
OUT (output) instruction
OUT 8-bit port address
This instruction is used to send data byte stored in the
accumulator (A) to the output port, whose address
specified in the instruction.
Flags?
LOGICAL OPERATIONS
• ANA (Logical AND with Accumulator) instruction
ANA R A←A&R
ANA M A ← A & [HL]
• ANI (AND Immediate with Accumulator) instruction
ANI 8-bit data A ← A & (8-bit data)
A A
No flag is modified.
LOGICAL OPERATIONS
(continued...)
• CMP (Compare) instruction
CMP R
The contents of the register R are compared with the
contents of the Accumulator (A).
Actually, the comparison is done by subtracting the contents
of the register R from the contents of the Accumulator (A).
The contents of the register R and the Accumulator do not
change.
All flags are modified similar to subtraction.
Compare Instruction
Although, all flags are modified, but the conclusion can be
made only by CY and Z flag, as shown below:
JZ (Jump on Zero)
JP (Jump on Plus)
JM (Jump on Minus)
0 1 D D D S S S
MOV Rd, Rs
0 1 0 0 0 0 0 1 = 41H
Opcodes of Various MOV
instructions
Source Registers
B C D E H L M A
Destination Registers
B 40 41 42 43 44 45 46 47
C 48 49 4A 4B 4C 4D 4E 4F
D 50 51 52 53 54 55 56 57
E 58 59 5A 5B 5C 5D 5E 5F
H 60 61 62 63 64 65 66 67
L 68 69 6A 6B 6C 6D 6E 6F
M 70 71 72 73 74 75 - 77
A 78 79 7A 7B 7C 7D 7E 7F
Opcode format of ADD instruction:
1 0 0 0 0 R R R
1 0 0 1 0 R R R
ADDRESSING MODES
Register Addressing
MOV C, B
Immediate Addressing
MVI A, 33H
Direct Addressing
STA 3050H
Indirect Addressing
MOV B, M
Assembly Language Programming
Write an assembly language program to add two 8-bit numbers stored in register
A and register B. Display the result at output port 01H.
2001H 20H
2002H MVI B, 30H 06H Store 30H in register B.
2003H 30H
2004H ADD B 80H Add contents of register B with A
and store the result in A.
2005H OUT 01H D3H Send the contents of A to output
port 01H.
2006H 01H
2007H HLT 76H Stop the program.
Write an assembly language program to add two 8-bit numbers
stored in register A and register B. Store the result at the
memory location 3000H using STA instruction.
Read A, B, C
STOP
Write an assembly language program to find the largest of the
given list of n data bytes stored in the memory starting from
memory location 2071H. Count of data bytes in the list (i.e. n)
is stored at memory location 2070H.
START
A>B?
No
Store larger
Yes number in A
No
Decrement
Counter C
C=0?
Yes
Display Highest
number
STOP
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2070H 21H Initialise the HL register pair with the memory address
2070H of the count.
2001H 70H
2002H 20H
2003H MOV C, M 4EH Copy count from memory to register C.
2004H XRA A AFH Clear the Accumulator, which will store the largest
number.
2005H INX H 23H Increment memory pointer to address 2071H, which is
the address of the first number.
2006H LOOP: MOV B, M 46H Copy number stored at address pointed by HL.
200CH SKIP: INX H 23H Increment memory pointer to the address of the next
number.
200DH DCR C 0DH Decrement the counter.
200EH JNZ LOOP C2H Repeat the process from location 2006H if counter is
not zero.
200FH 06H
2010H 20H
2011H OUT 01H D3H When counter reaches zero. Loop is terminated. A
contains the largest number, which is displayed at Port
2012H 01H 01H.
2013H HLT 76H Stop the program.
Write an assembly language program to add the given list of n data bytes
stored in the memory starting from memory location 3000H. Store the 8-bit
sum in the memory location 3050H. Where n may be any number but for
this case choose n=10.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 3000H 21H Store the starting address of the list of data bytes in HL register pair.
2001H 00H
2002H 30H
2003H MVI C, 0AH 0EH Initialise the counter with 0AH (= 10 in decimal).
2004H 0AH
2005H XRA A AFH Clear Accumulator.
2006H LOOP: ADD M 86H Add the data stored at memory location pointed by HL pair with A.
2007H INX H 23H Increment the memory pointer. Now, pointing to the next number.
2008H DCR C 0DH Decrement the counter.
2009H JNZ LOOP C2H Repeat the process, until the conter is zero.
200AH 06H
200BH 20H
200CH STA 3050H 32H Store the sum (available in A) at memory location 3050H.
200DH 50H
200EH 30H
200FH HLT 76H Stop the program.
Write an assembly language program to add the given list of n data bytes stored in
the memory starting from memory location 3050H. Store the 16-bit sum in the
memory location 3070H (lower byte) and 3071H (higher byte). Where n may be any
number but for this case choose n=25.
Memory Address Label Mnemonics Hex Remarks
Code
2000H LXI H, 3050H 21H Store the starting address of the list of data bytes in HL register
pair.
2001H 50H
2002H 30H
2003H MVI C, 19H 0EH Initialise the counter with 19H (= 25 in decimal).
2004H 19H
2005H XRA A AFH Clear the Accumulator. (A=00H)
2006H MOV B, A 47H Clear the register B. (B=00H).
2007H LOOP: ADD M 86H Add the data stored at memory location pointed by HL pair with A.
2008H JNC SKIP D2H If Carry flags is not set, goto memory location 200CH.
2009H 0CH
200AH 20H
200BH INR B 04H If Carry flag is set, B is incremented by one.
200CH SKIP: INX H 23H Increment the memory pointer. Now, pointing to the next number.
200DH DCR C 0DH Decrement the counter.
200EH JNZ LOOP C2H Repeat the process, until the conter is zero.
200FH 07H
2010H 20H
2011H STA 3070H 32H Store the low-order byte of the sum (available in A) at memory
location 3070H.
2012H 70H
2013H 30H
2014H MOV A, B 78H Copy high-order byte of the sum to A.
2015H STA 3071H 32H Store the high-order byte of the sum at memory location 3071H.
2016H 71H
2017H 30H
2018H HLT 76H Stop the program.
Write an assembly language program to add the set of data bytes stored in the
memory starting form 2050H. The end of data string is indicated by 00H. Result
may be larger than FFH. Display the sum at port 1 and port 2.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2050H 21H Store the starting address of the list of data bytes in HL register
pair.
2001H 50H
2002H 20H
2003H XRA A AFH Clear the Accumulator. (A=00H)
2004H MOV C, A 4FH Clear the register C. (C=00H).
2005H LOOP: MOV A, M 7EH Read first number in the Accumulator.
2006H CPI 00H FEH Check whether the number is 00H or not.
2007H 00H
2008H JZ DISPLAY CAH If it is 00H then goto 2015H to display the sum.
2009H 15H
200AH 20H
200BH ADD C 81H Otherwise Add the number in A with previous sum in C. Result is
stored in A.
200CH JNC SKIP D2H If Carry flags is not set, goto memory location 200CH.
200DH 10H
200EH 20H
200FH INR B 14H If Carry flag is set, B is incremented by one.
2010H SKIP: MOV C, A 4FH Save the low-order sum in C.
2011H INX H 23H Increment the memory pointer. Now, pointing to the next number.
2001H 50H
2002H 20H
2003H MOV C, M 4EH Store Count in C.
2004H XRA A AFH Clear Accumulator.
2005H MOV B, A 47H Clear B, which will be used to store the sum.
2006H INX H 23H Increment memory pointer.
2007H LOOP: MOV A, M 7EH Copy data stored in the memory location pointed by HL register
pair into A.
2008H RLC 07H Rotate Accumulator Left to put D7 bit in Carry flag.
2009H JC REJECT DAH If Carry flag is set by RLC instruction, i.e., the number in
Accumulator was negative. Reject the number and jump to 200EH.
200AH 0EH
200BH 20H
200CH RRC 0FH If Carry flag is not set. Rotate right the Accumulator to get the
original number in the Accumulator.
200DH ADD B 80H Add the positive number with the previous sum stored in B.
200EH MOV B, A 47H Store the new sum in B
200FH REJECT: INX H 23H Increment the memory pointer.
2010H DCR C 0DH Decrement counter.
2011H JNZ LOOP C2H Repeat the process from 2007H, until counter reaches zero.
2012H 06H
2013H 20H
2014H MOV A, B 78H Copy the final sum from B to A.
2015H STA 3070H 32H Store the contents of A in memory location 3070H.
2016H 70H
2017H 30H
2018H HLT 76H Stop the program.
Write an assembly language program to copy a block of data bytes from one
memory location starting from 2051H to another section of memory starting
from 3051H. Number of bytes to be copied is given at memory location 2050H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2050H 21H Initialise memory pointer with the address of the memory
location where the count is stored.
2001H 50H
2002H 20H
2003H LXI D, 3051H 11H Store the starting memory address of the destination in DE
register pair.
2004H 51H
2005H 30H
2006H MOV C, M 4EH Store the count from memory location pointed by HL pair to
C.
2007H INX H 23H Increment memory pointer; now pointing to starting
memory address of the source.
2008H LOOP: MOV A, M 7EH Copy source data from the memory location pointed by HL
pair into A.
2009H STAX D 12H Copy data in A to destination memory location pointed by
DE pair.
200AH INX H 23H Increment source address.
200BH INX D 13H Increment destination address.
200CH DCR C 0DH Decrement counter.
200DH JNZ LOOP C2H Repeat the process from 2008H, until counter reaches zero.
200EH 08H
200FH 20H
2010H HLT 76H Stop the program.
Write an assembly language program to exchange a block of data bytes stored in the
memory starting from 2051H with a block of data bytes stored at another section of
memory starting from 3051H. Number of bytes to be exchanged is given at memory
location 2050H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2050H 21H Initialise memory pointer with the address of the memory
location where the count is stored.
2001H 50H
2002H 20H
2003H LXI D, 3051H 11H Store the starting memory address of the destination in DE
register pair.
2004H 51H
2005H 30H
2006H MOV C, M 4EH Store the count from memory location pointed by HL pair to C.
2007H INX H 23H Increment memory pointer; now pointing to starting memory
address of the source.
2008H LOOP: MOV A, M 7EH Read source data into A.
200DH STAX D 12D Store source data at destination location pointed by DE pair.
200EH INX H 23H Increment source pointer.
200FH INX D 13H Increment destination pointer.
2010H DCR C 0DH Decrement counter.
2011H JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.
2012H 08H
2013H 20H
2014H HLT 76H Stop the program.
Write an assembly language program for shifting of block of data from memory
locations 3000H – 3009H to new memory locations 3050H – 3059H in reverse order.
i.e., data from 3000H will be moved to 3059H and so on.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 3000H 21H Initialise the source pointer (i.e., HL pair) with the starting address of the
source data
2001H 00H
2002H 30H
2003H LXI D, 3059H 11H Initialise destination pointer (i.e., DE pair) with the last address of the
destination
2004H 59H
2005H 30H
2006H MVI C, 0AH 0EH Initialise the counter with 0AH (= 10 in decimal) as given in the
question.
2007H 0AH
2008H LOOP: MOV A, M 7EH Read the source data from the memory location pointed by HL pair.
200EH 08H
200FH 20H
2010H HLT 76H Stop the program.
Write an 8085 assembly program to check if the Input string of characters (in ASCII
codes) stored at location 2050H to 205FH is equal to a string stored at location 2100H to
210FH (in ASCII codes). If two strings are same, display 1 at Port 1, otherwise 0.
Memory Address Label Mnemonics Hex Remarks
Code
2000H LXI D, 2050H 11H Initialise DE pair with the starting address of first data set.
2001H 50H
2002H 20H
2003H LXI H, 2100H 21H Initialise HL pair with the starting address of second data set.
2004H 00H
2005H 21H
2006H MVI C, 10H 0EH Initialise counter with 10H (= 16 in decimal).
2007H 10H
2008H MVI B, 00H 06H Initialise B with 00H.
2009H 00H
200AH LOOP: LDAX D 1AH Read data of the first set from the memory location pointed by DE pair
into A.
200BH CMP M BEH Compare data in A with respective data of the second set pointed by HL
pair.
200CH JNZ EXIT C2H If Zero flag is not set, i.e., data does not match then jump to 2017H,
where 00H from B is copied to A and displayed.
200DH 16H
200EH 20H
200FH INX H 23H Otherwise increment HL pair.
2010H INX D 13H Increment DE pair.
2011H DCR C 0DH Decrement counter.
2012H JNZ LOOP C2H Repeat the process from 200AH, until counter reaches zero.
2013H 09H
2014H 20H
2015H MVI B, 01H 3EH Store 01 in B, if data set match is successful.
2016H 01H
2017H EXIT: MOV A, B 78H Copy contents of B in A.
2018H OUT 01H D3H Display the contents to A.
2019H 01H
HLT 76H Stop the program.
Write an assembly language program to search a data byte, stored at memory location 3000H in the list of 100
data bytes stored in the memory starting from location 3001H. If the data byte is found, display 01H and if not
found display 00H, on the output port 82H.
2001H 00H
2002H 30H
2003H MOV A, M 7EH Copy the data byte to be searched into A.
2004H MVI B, 01H 06H Store 01H in B. Register B is used to store the value to be displayed.
2005H 01H
2006H MVI C, 64H 0EH Initialise the counter with 64H (=100 in decimal) as given in the
question.
2007H 64H
2008H INX H 23H Increment the memory pointer; now pointing to first data in the list.
2009H LOOP: CMP M BEH Compare the data byte to be searched (in A) with data in the list at
memory location pointed by HL pair.
200AH JZ END CAH If zero flag is set, i.e., match is found, then stop the comparison and
200BH 14H jump to memory location 2014H.
200CH 20H
200DH INX H 23H Otherwise increment HL pair.
200EH DCR C 0DH Decrement counter
200FH JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.
2010H 09H
2011H 20H
2012H MVI B, 00H 06H Store 00H in B.
2013H 00H
2014H END: MOV A, B 78H Copy the contents of B in A.
2016H 82H
2017H HLT 76H Stop the program.
Write a program to multiply two 8-bit numbers. Multiplicand is extended to 16-bit
and stored in the two consecutive memory locations 2050H and 2051H. The multiplier
is stored at 2052H. Store the 16-bit product at two consecutive memory locations
2053H and 2054H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LHLD 2050H 2AH Load HL pair with 16-bit multiplicand stored at 2050H and 2051H.
2001H 50H
2002H 20H
2003H XCHG EBH Exchange the contents of HL with DE pair. Multiplicand is now in DE pair.
2004H LDA 2052H 3AH Load 8-bit multiplier into Accumulator.
2005H 52H
2006H 20H
2007H LXI H, 0000H 21H Copy 0000H in HL pair.
2008H 00H
2009H 00H
200AH MVI C, 08H 0EH Initialise counter with 08H.
200BH 08H
200CH LOOP: DAD H 29H Add HL with HL to shift the contents of HL left by one position.
200DH RAL 17H Shift the contents of Accumulator left by one position.
200EH JNC SKIP D2H If Carry flag is not set skip following DAD D instruction.
200FH 12H
2010H 20H
2011H DAD D 19H Add DE with HL. Store result in HL.
2012H SKIP: DCR C 0DH Decrement counter.
2013H JNZ LOOP C2H Repeat the process from 200CH, until counter reaches zero.
2014H 0CH
2015H 20H
2016H SHLD 2053H 22H Store result in HL to the memory locations 2053H & 2054H.
2017H 53H
2018H 20H
2019H HLT 76H Stop the program.
Write an assembly language program to divide a 16-bit dividend, stored in memory
locations 2051H & 2052H, by an 8-bit divisor, stored in memory location 2053H. After
division the quotient must be stored in memory location 2054H and remainder in
memory location 2055H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LHLD 2051H 2AH Load 16-bit dividend in HL register pair from the memory locations 2051H &
2052H
2001H 51H
2002H 20H
2003H LDA 2053H 3AH Load 8-bit divisor into A from memory location 2053H.
2004H 53H
2005H 20H
2006H MOV B, A 47H Copy A into B.
2008H 08H
2009H LOOP: DAD H 29H Shift Dividend and quotient left by one position.
200AH MOV A, H 7CH Copy high-order byte of the dividend in A
200BH SUB B 90H Subtract divisor form high-order byte of the dividend.
200CH JC SKIP DAH If high-order byte of the dividend is less than divisor then go to 200FH.
200DH 0FH
200EH 20H
200FH MOV H, A 67H Otherwise copy high-order into H.
2013H 09H
2014H 20H
2015H SHLD 2054H 22H Store the result in Hl pair at memory locations 2054H & 2055H
2016H 54H
2017H 20H
2018H HLT 76H Stop the program.
Write an assembly language program to perform addition of two
Hexadecimal Numbers as given below:
9A5B8938H & 8BC34AD1H
2001H 60H
2002H 20H
2003H MOV C, M 4EH Store the count in C (counter 1).
2004H DCR C 0DH Decrement Counter 1.
2005H DOPASS: LXI H, 2061H 21H Initialise HL pair with the memory address of the first number in the list.
2006H 61H
2007H 20H
2008H MOV D, C 51H Copy counter 1 into counter 2.
2009H CHECK: MOV A, M 7EH Read one number into the accumulator.
200AH INX H 23H Increment HL pair pointing to next number in the list.
200BH MOV B, M 46H Copy next number in register B.
200CH DCX H 2BH Decrement HL register pair to get the previous address.
200DH CMP B B8H Compare two adjacent numbers.
200EH JNC NOSWAP D2H If later number is smaller, then no swap.
200FH 15H
2010H 20H
2011H MOV M, B 70H Swapping.
2012H INX H 23H
2013H MOV M, A 77H
2014H DCX H 2BH
2015H INX H 23H
2016H NOSWAP: DCR D 15H Decrement counter 2.
2017H JNZ CHECK C2H Repeat process from 2009H, until counter 2 is not zero.
2018H 09H
2019H 20H
201AH DCR C 0DH Decrement counter 1.
201BH JNZ DOPASS C2H Repeat for next pass, until counter 1 is not zero.
201CH 05H
201DH 20H
201EH HLT 76H Stop the program.