You are on page 1of 92

By: Dr.

Anil Swarnkar
Assistant Professor
Electrical Engineering Department.,
MNIT, Jaipur

E-mail id: aswarnkar.ee@mnit.ac.in


Mobile: 98292-88581
What is Microprocessor
VLSI technology of IC’s made it possible to design the
complete circuit of ALU (Arithmetic Logic Unit) and
CU (Control Unit) within a single chip, which
comprises the main processing part, called Central
Processing Unit (CPU), of computer system. This chip
was named Microprocessor.
Importance of Microprocessors
Microprocessors/microcontrollers are not used only in
computer systems but may be used in many control
applications and devices used in our daily life.
For such applications use of advanced microprocessors
may be a costly affair, hence smaller processors like
8085/86, or microcontrollers with limited features may be
more suitable and cost effective.
Temperature Control System
8085 Microprocessor
Accumulator (A)
It is an 8-bit register, which is the most important part of
the arithmetic and logic unit (ALU). It is used to store 8-
bit data. The results of arithmetical and logical operations
are stored in the accumulator. It is also used to receive
data from input port to microprocessor and to send data to
output port from microprocessor. It is referred as register
A in the program.
General Purpose Registers
• Registers B, C, D, E, H and L are 8-bit general-purpose
registers. These registers store 8-bit data temporarily for
processing.
• Some time it is required to store 16-bit data. In 8085
microprocessor, BC, DE and HL are used as register pairs
to store 16-bit data.
• Hence there are 6 general-purpose 8-bit registers and they
can be used as 3 pairs as 16-bit registers.
Flag Register (F)
Flag register is also an 8-bit register. Out of 8-bits, five bits are
defined as flags to indicate status of the accumulator (with
some exceptions), hence it is also called status register. Flags
are flip-flops, which can be set or reset. After any
arithmetical/logical operation some or all flags are modified
according to the result of operation. Flag register, showing the
bit position reserved for various flags
 Sign flag (S): If D7 bit (left most bit) of
accumulator (with some exceptions) is 1, as a
result of any arithmetical or logical
operation, Sign flag (S) is set (bit
corresponding to sign flag is modified to 1 in
the flag register), otherwise reset (bit
corresponding to sign flag is modified to 0).
Representation of negative
number
In 8085 negative numbers are represented in 2’s
complement form and subtraction is performed using 2’s
complemented method. If the result of subtraction is
negative, it will also be in 2’s complement form. Bit D7
(left most bit) is used to indicate sign of a number. If D7
is 0; the number is positive and if D7 is 1; the number is
negative. D7 is 1 for 2’s complement of all 7-bit numbers.
8-bit Binary Decimal number
number Signed Unsigned

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).

Auxiliary Carry flag (AC): If carry is generated from D3 to D4 in the


accumulator after any arithmetical or logical operation, Auxiliary Carry flag
(AC) is set (1), otherwise reset (0). This flag is used internally by the
microprocessor for BCD operations and cannot be used by the programmer.

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)

It is also a 16-bit register and a memory pointer


similar to Program Counter. It holds the memory
address of the top of the stack.
Bus Organisation
There are three sets of busses in 8085-microprocessor.
Address bus, Data bus and Control bus
Basic Operations of
8085-microprocessor

 Opcode Fetch: Reading and decoding operation code of


an instruction.
 Memory Read: Reading data from memory.
 Memory Write: Writing data into memory.
 I/O Read: Accepting data from Input Port.
 I/O Write: Sending data to Output Port.
Memory Read Operation
Pins and Signals
• Higher Order Address Bus
• Multiplexed Address/data Bus
• Control signals
• Status signals
• Power supply and clock frequency
• Interrupt signals
• Other externally initiated signals
• Serial Input/Output ports
Pins and Signals of 8085-microprocessor

S0
S1
 Higher Order Address Bus

The 8085-microprocessor has 8 pins dedicated to higher order


address A8-A15. These pins are used to connect higher order address
bus. These pins generate output signals, i.e. the bus is
unidirectional.

 Multiplexed Address/Data 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.

WR (Write signal) – It is also an active low control signal. It goes low


when write operation (i.e. writing into memory/output port) takes place.

ALE (Address Latch Enable signal) – It is an active high signal. It goes


high during first clock cycle and enables the latch used to demultiplex
address bus from data bus. Demultiplexing address and data bus is
explained later in this chapter.
Status signals
There are three status signals- IO/M, S0 and S1. All these
signals are output signals.
IO/M – It is a status signal, used to distinguish whether the
operation is related to I/O or Memory. If it is high (1), the
operation is related to I/O; if it is low (0), the operation is
related to memory.
S0 and S1 – Similar to IO/M these signals are also used to
differentiate various operations.
Operations S1 S0
Halt 0 0
Write 0 1
Read 1 0
Opcode Fetch 1 1
Status and control signals
during various operations
Operations Status Signal Control Signals
IO/M S1 S0 RD WR
Opcode Fetch 0 1 1 0 1
Memory Read 0 1 0 0 1
Memory Write 0 0 1 1 0
I/O Read 1 1 0 0 1
I/O Write 1 0 1 1 0
Halt Z 0 0 Z Z

Z= Tri-state (High Impedance)


De-multiplexing
Assembly Language Instructions

• An instruction is a binary pattern, which when applied to


the microprocessor digital circuit (architecture) - a specific
task is performed.
• The entire group of instructions of particular
microprocessor is called its instruction set. In 8085-
microprocessor each instruction code is of 8-bits (1 byte),
hence there may 28 (=256) different binary patterns;
therefore total 256 instructions in its instruction set.
Classification of Instructions
 Data copy operations
 Input/Output operations
 Arithmetic operations
 Logical operations
 Branch operations
 Machine control operations
 Stack Operations
Data Copy Operations

 These instructions are used to copy data


 From one register to another register
 8/16-bit data directly from the instruction to any register
 Data from any register to memory
 Data from memory to any register
MOV (Move) instruction
 Copies the contents of the source into destination.

MOV destination, source


Format 1: MOV Rd, Rs
From one register to another register, i.e., Rd ← Rs

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.

[Output port address] ← A


ARITHMETIC OPERATIONS
• ADD instruction
– ADD R A←A+R
– ADD M A ← A + [HL]
• ADI (Add Immediate) instruction
– ADI 8-bit data A ← A + (8-bit data)
• ADC (Add with Carry) instruction
– ADC R A ← A + R + CY
– ADC M A ← A + [HL] + CY
• ACI (Add Immediate with Carry) instruction
– ACI 8-bit data

Flags are modified according to the result.


• DAD (Double Add) instruction
– DAD Rp HL ← HL + Rp

Flags: If result is larger than 16-bit, the CY flag is set. No


other flags are affected.
Ex.: Execution of ADD B instruction
ARITHMETIC OPERATIONS
(Continued ...)
 SUB (Subtract) instruction
 SUB R A←A–R
 SUB M A ← A – [HL]
 SUI (Subtract Immediate) instruction
 SUI 8-bit data A ← A – 8-bit data
 SBB (Subtract with Borrow) instruction
 SBB R A ← A – (R + Borrow)
 SBB M A ← A – ([HL] + Borrow)
 SBI 8-bit data A ← A – (data + Borrow)

All Flags are modified according to the result.


Steps for subtract operation:
 Step 1: Converts subtrahend (the number to be
subtracted) into its 1’s complement form.
 Step 2: Adds 1 to the 1’s complement form to obtain 2’s
complement form of the subtrahend.
 Step 3: Add 2’s complement to the minuend (the
contents of the accumulator).
 Step 4: Complement the Carry flag.
Ex.: Execution of SUB C instruction
ARITHMETIC OPERATIONS
(continued ...)
 INR (Increment) instruction
 INR R R←R+1
 INR M [HL] ← [HL] + 1
 DCR (Decrement) Instruction
 DCR R R←R–1
 DCR M [HL] ← [HL] – 1
 INX (Increment Register Pair) instruction
 INX Rp Rp ← Rp + 1
 DCX (Decrement register pair) instruction
 DCX Rp Rp ← Rp – 1

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)

S, Z, and P are modified according to the result. CY is


always reset. AC is always set.
LOGICAL OPERATIONS
(continued...)
• ORA (Logical OR with Accumulator) instruction
 ORA R A←A|R
 ORA M A ← A | [HL]
• ORI (OR Immediate with Accumulator) instruction
 ORI 8-bit data

S, Z, and P are modified according to the result. CY and AC


are always reset.
LOGICAL OPERATIONS
(continued...)
• XRA (Exclusive-OR with Accumulator) instruction
 XRA R
 XRA M
• XRI (Exclusive-OR Immediate with Accumulator)
instruction
 XRI 8-bit data

S, Z, and P are modified according to the result. CY and AC


are always reset
LOGICAL OPERATIONS
(continued...)
CMA (Complement Accumulator) instruction
Format: CMA
 Complements the contents of the Accumulator (A). i.e., In
the Accumulator all ones are converted to zeros and all zeros
are converted to ones.

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:

 If A > R; CY and Z flags are reset.


 If A = R; Z flag is set and CY flag is reset.
 If A < R; CY is set and Z flag is reset.
More compare instructions
 Compare A with the contents of memory
 CMP M
• CPI (Compare Immediate) instruction
 CPI 8-bit data
Logical Instructions (continued...)
RAL (Rotate Accumulator Left through Carry) instruction
Format: RAL
Logical Instructions (continued...)
• RLC (Rotate Accumulator Left) instruction
Format: RLC
Logical Instructions (continued...)
• RAR (Rotate Accumulator Right through Carry)
instruction
Format: RAR
Logical Instructions (continued...)
• RRC (Rotate Accumulator Right) instruction
Format: RRC
BRANCH OPERATIONS
 Jump instructions
 Unconditional Jump instruction
Format: JMP 16-bit memory address
 Conditional Jumps instructions
 JC (Jump on Carry)

 JNC (Jump on No Carry)

 JZ (Jump on Zero)

 JNZ (Jump on No Zero)

 JP (Jump on Plus)

 JM (Jump on Minus)

 JPE (Jump on Parity Even)

 JPO (Jump on Parity Odd)


BRANCH OPERATIONS (continued..)
 Unconditional Call instruction
Format: CALL 16-bit memory address
 Conditional Call Instructions
 CC (Call on Carry)
 CNC (Call on No Carry)
 CZ (Call on Zero)
 CNZ (Call on No Zero)
 CP (Call on Plus)
 CM (Call on Minus)
 CPE (Call on Parity Even)
 CPO (Call on Parity Odd)
BRANCH OPERATIONS
(continued..)
• Unconditional Return Instruction
Format: RET
 Conditional Return Instructions
 RC (Return on Carry)
 RNC (Return on No Carry)
 RZ (Return on Zero)
 RNZ (Return on No Zero)
 RP (Return on Plus)
 RM (Return on Minus)
 RPE (Return on Parity Even)
 RPO (Return on Parity Odd)
BRANCH OPERATIONS (continued..)
 RST (Restart) instructions
 Format: RST n
Where n may be 0-7.

Restart Instructions Called Locations


RST 0 0000H
RST 1 0008H
RST 2 0010H
RST 3 0018H
RST 4 0020H
RST 5 0028H
RST 6 0030H
RST 7 0038H
PCHL (Load PC with HL) instruction
Format: PCHL
This is a special instruction, which copies the contents of
HL register pair into the Program Counter (PC) register.
Hence the program execution is transferred to the memory
location specified by HL register pair.
MACHINE CONTROL INSTRUCTIONS
 HLT (Halt) instruction
 Format: HLT
 NOP (No Operation) instruction
 Format: NOP
 STC (Set Carry) instruction
 Format: STC
 CMC (Complement Carry) instruction
 Format: CMC
 EI, DI, SIM and RIM insructions
STACK OPERATIONS
 Initialise Stack Pointer
 LXI SP, 16 bit
 PUSH instruction
 PUSH Rp
 PUSH PSW
 POP instruction
 POP Rp
 POP PSW
 XTHL (Exchange Top of the stack with HL) instruction
 L <-> [SP]; H <-> [SP+1]
 SPHL (Load Stack Pointer with HL)
 SP <- HL
INSTRUCTION SIZE
According to the size 8085 instructions are classified into
following three groups:

 One Byte Instructions


 Two Byte Instructions
 Three Byte Instructions
OPCODE FORMAT
The instructions, which use registers or register pairs as
their operands, have following codes somewhere in their
opcode byte.

Registers Code Register Pairs Codes


B 000 BC 00
C 001 DE 01
D 010 HL 10
E 011 AF (PSW) or 11
SP
H 100
L 101
A 111
M (memory) 110
MOV instruction
Opcode format of MOV instruction is as follows:

0 1 D D D S S S

MOV Rd, Rs

Example: opcode of MOV B, C is

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

Opcode format of SUB instruction:

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.

Memory Mnemonics Hex Remarks


Address Code
2000H MVI A, 20H 3EH Store 20H in register A.

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.

Memory Mnemonics Hex Remarks


Address Code

2000H MVI A, 20H 3EH Store 20H in register A.


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 STA 3000H 32H Store the contents of A (i.e. result) at
2006H 00H the memory location 3000H.
2007H 30H
2008H HLT 76H Stop the program.
What is Masking? Assume that 37H is stored in the
Accumulator. Mask high-order 4-bits of the given data and
display the result on the output port 02H.

Memory Mnemonics Hex Remarks


Address Code

2000H MVI A, 37H 3EH Store 37H in register A.


2001H 37H
2002H ANI 0FH E6H AND the contents of A with 0FH.
2003H 0FH (Masking high-order 4-bits)

2004H OUT 02H D3H Display the contents of A on output port


2005H 02H 02H.
2006H HLT 76H Stop the program.
Add two 8-bit numbers stored in memory location 2050H
and 2051H and store the result at memory location 2052H.

Memory Mnemonics Hex Code Remarks


Address
2000H LXI H, 2050H 21H Load memory address of the first
2001H 50H number in HL register pair.
2002H 20H
2003H MOV A, M 7EH Copy first number into A.
2004H INX H 23H Increment the contents of HL
pair. HL pair now pointing to
second number.
2005H ADD M 86H Add first & second numbers.
2006H STA 2052H 32H Store the result at memory
2007H 52H location 2052H.
2008H 20H
2009H HLT 76H Stop the program.
Write an assembly language program to find the largest of three
numbers stored in the memory location 2050H, 2051H and
2052H, assuming that all three numbers are unequal.
START

Read A, B, C

Yes (CY=0) A>B? No (CY=1)

A>C? No (CY=1) No (CY=1) B>C?


Yes (CY=0)
Yes (CY=0)

Display A Display C Display B

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

Initialise Memory Pointer


Initialise Counter C
A=0

Read number from the list


store in B

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.

2007H CMP B B8H Compare A with B. All flags are modified.


2008H JNC SKIP D2H If Carry flag is not set (B<A) then goto memory
location 200CH.
2009H 0CH
200AH 20H
200BH MOV A, B 78H If B>A. Store larger number in A.

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.

2012H JMP LOOP C3H Repeat the process.


2013H 05H
2014H 20H
2015H DISPLAY: MOV A, B 78H Copy high-order sum in A.
2016H OUT PORT1 D3H Display it at PORT 1.
2017H PORT1
2018H MOV A, C 79H Copy low-order sum in A.
2019H OUT PORT2 D3H Display it at PORT 2.
201AH PORT2
201BH HLT 76H Stop the program.
Write an assembly language program to find the sum of positive numbers only and ignore negative
numbers from the list of numbers. The length of the list is in memory location 2050H and the series
itself begins from memory location 2051H. Store the 8-bit sum at the memory location 3070H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2050H 21H Initialise Memory Pointer with the memory address of the count.

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.

2009H MOV B, A 47H Save it in B.

200AH LDAX D 1AH Read destination data in A.


200BH MOV M, A 77H Store destination data at source location pointed by HL pair.

200CH MOV A, B 78H Get source data in 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.

2009H STAX D 12H Store at destination address pointed by DE pair.

200AH INX H 23H Increment source pointer.


200BH DCX D 1BH Decrement destination pointer.
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 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.

Memory Label Mnemonics Hex Remarks


Address Code
2000H LXI H, 3000H 21H HL pair is initialised with the memory address 3000H, where the data
byte to be searched is stored.

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.

2015H OUT 82H D3H Display the contents of 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.

2007H MVI C, 08H 0EH Initialise Counter with 08H.

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.

2010H INR L 2CH Increment the quotient by one.


2011H SKIP: DCR C 0DH Decrement the count.
2012H JNZ LOOP C2H Repeat the process from 2009H, until counter reaches zero.

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

Memory Label Mnemonics Hex Remarks


Address Code
2000H LXI H, 3000H 21H Load starting address of the first set of bytes in HL
register pair.
2001H 00H
2002H 30H
2003H LXI D, 3051H 11H Load starting address of the second set of bytes in DE
register pair.
2004H 50H
2005H 30H
2006H MVI C, 04 0EH Load the counter with 4, as 4 bytes in each number
given in the question.
2007H 04H
2008H XRA A AFH Clear the Accumulator and Carry Flag.
2009H LOOP: LDAX D 1AH Load accumulator with the first byte of the second
number, stored in the memory location pointed by DE
pair.
200AH ADC M 8EH Add Accumulator with the first byte of the first number
with carry.
200BH MOV M, A 77H Store the result in the memory pointed by the HL pair.
Overwriting the first number.
200CH INX H 23H Increment the memory pointer of the first number.
200DH INX D 13H Increment the memory pointer of the second number.
200EH DCR C 0DH Decrement the counter.
200FH JNC LOOP C2H Repeat the process from 2009H, until counter reaches
zero.
2010H 09H
2011H 20H
2012H HLT 76H Stop the program.
Write an assembly language program to sort the list of bytes, in ascending order, stored
in the memory starting from 2061H. The count of the bytes in the list is stored at
memory location 2060H.
Memory Label Mnemonics Hex Remarks
Address Code
2000H LXI H, 2060H 21H Load the HL pair with the memory address where the count of the list is stored.

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.

You might also like