Microprocessor For Memory Mapping and Instruction Set
Microprocessor For Memory Mapping and Instruction Set
By
Ram Niwas (IES)
4
Memory Mapping
4.1 Introduction
Memory is an integral part of a microcomputer system. It is used to store instructions and
data in binary format for the microprocessor. Memory can be of two types i.e. prime (or
main) memory and storage memory. Read/Write Memory (R/W M) and Read Only Memory
(ROM) are examples of main or prime memory and magnetic tapes or hard disk is example
of storage or secondary memory.
58 By Dr. Ram Niwas, IES Microprocessor 8085
The R/W memory consists of registers which are made of group of flip-flops that store bits
of information. These flip-flops are called memory cells. The number of bits stored in a
register is called a memory word. In a memory chip, all registers are arranged in a sequence
and identified by binary numbers called memory addresses. To communicate with memory.
the MPU should be able to
(i) select the chip,
(ii) identify the register, and
(iii) read from or write into the register.
The MPU uses its address bus to send the address of a memory register and uses the data
bus and control lines to read from or write into that register.
Input data can be written into the latch by enabling the input buffer using active low WR
signal and can be read from it by enabling the output buffer using active low RD signal.
This latch, with read and write enable signals which can store one binary bit, is called a
memory cell.
Fig. 4.3 shows a 8 bit register consisting of eight such cells or latches grouped together. This
register has eight input lines and eight output lines and can store eight bits; thus the size of
the memory word is eight bits. The size of this register is specified either as 8-bit or 1 × 8-
bit, which indicates one register with eight cells or eight I/O lines.
rra
Memory Mapping By Dr. Ram Niwas, IES 59
rra
Memory Mapping By Dr. Ram Niwas, IES 61
Fig. 4.8 shows two memory chips, with an additional signal called Chip Select (CS), and A 2
(with an inverter) is used to select between the chips. When A2 is 0 (low), chip 1 is selected,
and when A2 is 1 (high), chip 2 is selected. The addresses on A 1 and A0 determine the
registers to be selected; thus, by combining the logic on A2, A1 and A0, the memory addresses
range from 000 to 111. The concept of the Chip Select signal helps in designing chips and
allows us to expand memory size by using multiple chips.
Ex.4.1 Find the address range for 4K RAM used in 8085 microprocessor if CS = A15 A14 A13 is
used as the chip select logic .
Solution :
For 4K RAM (4 1024 = 212) the number of address lines required would be 12. So, out
of 16 address line 12 address line (i.e. A11 to A0) are used for addressing the memory
location in a chip and remaining four(i.e. A15 to A12) are used for selecting the chip. Here,
chip select signal is CS = A15 A14 A13 , so, the address lines A15 = 0 , A14=1 and A13= 1. The
line A12 may be 0 or 1 and accordingly range will be available.
The range of memory location with CS = A15A14 A13 will be as follows,
Case-I : Taking A12 = 0
rra
Memory Mapping By Dr. Ram Niwas, IES 63
So, address range is 6000H to 6FFFH with A12 = 0
Case-II : Taking A12 = 1
Solution :
For chip select CS signal to be low, A12 = 0, A13 =1 , A14 =1 , A15 =1 , the address range
with this combination will be as under,
A15 A14 A13 A12 A11 A10 A 9 A8 A 7 A 6 A5 A 4 A 3 A 2 A1A 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 = E000H
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 = EFFFH
chip select register select
When chip select signal is CS = A9 A8 , the address lines A9 = 0 and A8 =1. The lines
A10 to A15 are unused and so they are don’t care and lines A0 to A7 may be 0 or 1. The range
of memory locations with CS = A9 A8 will be as follows,
The address range covered by above combination of address line may vary from 0100 H to
FDFFH.
When chip select signal is CS = A9 A8 , the address lines A9 = 1 and A8 =0. The lines
A10 to A15 are don’t care and lines A0 to A7 may be 0 or 1. The range of memory locations
with CS = A9 A8 will be as follows,
The address range covered by above combination of address line may vary from 0200 H to
FE00H.
In F800 H address A8 =0 and A9 =0. So, neither of chip is selected for address F800H.
Therefore, the address range F800 – F9FF is NOT represented by chip # 1 and chip #2.
rra
Memory Mapping By Dr. Ram Niwas, IES 65
4.3 Memory Requirement and Memory Model
1. Address lines are used to identify a register in a memory chip. The number of address
lines required is determined by the number of registers in a chip (2n = Number of registers;
where n is the number of address lines). The 8085 microprocessor has 16 address
lines. Of these 16 lines, the address lines necessary for the memory chip must be connected
to the memory chip.
2. A memory chip requires a Chip Select CS signal to enable the chip. The remaining
address lines of microprocessor which are not connected to address lines of memory
chip can be connected to the CS signal through a chip select logic circuit.
3. The address lines which are neither used for Chip select logic nor used for enabling the
register in a chip should be left as don’t care. Such lines should be used as don’t care for
determining the address range of memory chip.
4. The address lines connected to CS select the chip, and the address lines connected to
the address lines of the memory chip select the register. Thus the memory address of a
register is determined by the logic levels (0/1) of all the address lines (including the
address lines used for CS ).
5. The control signal Read ( RD ) enables the output buffer and data from the selected
register are made available on the output lines. Similarly, the control signal Write ( WR )
enables the input buffer, and data on the input lines are written into memory cells. The
microprocessor can use its Memory Read and Memory Write control signals to enable
the buffers and the data bus to transport the contents of the selected register between
the microprocessor and memory.
6. The memory address range of a given chip can be changed by changing the hardware of
the Chip Select (CS) line. This line is also known as the Chip Enable (CE) line.
The models of a Read and Write Memory and the Read-Only Memory is shown in Fig.
4.10. The only difference between the two as far as addressing is concerned is that
ROM does not need the WR signal.
rra
Memory Mapping By Dr. Ram Niwas, IES 67
will match the memory requirements with the microprocessor signals. Microprocessor
8085 has 16 address lines available for memory. That means it is capable of identifying
216 (65536) memory registers, each register with a 16-bit address. The entire memory
addresses can range from 0000 to FFFF in Hex. Memory addresses provide the locations
of various memory devices in the system, and the interfacing logic defines the range of
memory addresses for each memory device.
Let us assume that we have a memory chip with 256 registers. Therefore, we need only 256
numbers (out of 65,536) that require eight address lines (28 = 256), the remaining eight lines
are used for the Chip Select through appropriate logic circuit. The address range of a
memory chip can be modified by modifying the chip select logic.
A group of 1024 registers is designated as 1K memory. Therefore a 1K-byte memory chip
has 1024 registers with 8 bits each. Similarly, a group of 256 registers is defined as one page
and each register is viewed as a line on the page . With this analogy, we can view 1K-byte
memory as a chip with four pages (1024/256 = 4) with each page having 256 registers.
Fig.4.11 :Tri-State Inverters with Active High and Active Low Enable Lines
68 By Dr. Ram Niwas, IES Microprocessor 8085
A tri-state logic device has a third line called Enable, as shown in Fig.4.11. When this
line is activated, the tri-state device functions the same way as ordinary logic devices,
when the third line is disabled, the logic device goes into the high impedance state-as if
it were disconnected from the system.
In microcomputer systems, peripherals are connected in parallel between the address
bus and the data bus through tri-state interfacing devices, so that peripherals do not
load the system buses. The microprocessor communicates with one device at a time by
enabling the tri-state line of the interfacing device. Tri-state logic is critical to proper
functioning of the microcomputer.
4.8.2 Buffer
The buffer is a logic circuit that amplifies the current or power. It has one input line and
one output line. The logic level of the output is the same as that of the input; logic 1
input provides logic 1 output (the opposite of an inverter). The buffer is used primarily
to increase the driving capability of a logic circuit. It is also known as a driver.
GATE QUESTIONS
Q.1 A memory system has a total of 8 memory chips, each with 12 address lines and 4 data
lines. The total size of the memory system is
(a) 16 kbytes (b) 32 kbytes
(c) 48 kbytes (d) 64 kbytes
GATE(EE, 03)
Q.2 An 8-bit microcontroller has an external RAM in the memory map from 8000H to 9FFFH.
The number of bytes this RAM can store is
(a) 8193 (b) 8191
(c) 8192 (d) 8000
rra
Memory Mapping By Dr. Ram Niwas, IES 69
GATE(IN, 05)
Q.3 An I / O peripheral device shown in Fig. (b) below is to be interfaced to an 8085 microproc-
essor. To select the I / O device in the I / O address range D4 H - D7 H, its chip-select
CS should be connected to the output of the decoder shown in Fig. (a) below:
Fig. (b)
(a) output 7 (b) output 5
(c) output 2 (d) output 0
GATE(EC, 06)
Q.4 An 8085 microprocessor based system uses a 4K 8 bit RAM whose starting address is
AA00 H. The address of the last byte in this RAM is
(a) 0FFF H (b) 1000 H
(c) B9FF H (d) BA00 H
GATE(EC, 01)
Q.5 An 8-bit DAC is interfaced with a microprocessor having 16 address lines (A 0 ... A15) as
shown in the adjoining figure. A possible valid address for this DAC is
rra
Memory Mapping By Dr. Ram Niwas, IES 71
The interfacing circuit makes use of 3 Line to 8 Line decoder having 3 enable lines E1 , E 2 , E3 .
The address of the device is
(a) 50 H (b) 5000 H
(c) A0 H (d) A000 H
GATE (2014/EE-I/2 M)
Fig. (b)
For enabling the decoder, chip select ( CS ) of decoder should be low and it is low when
address lines A15 is low and for generation of chip select signal ( CS ) of DAC memory, the
output line b2 of decoder should be selected. Line b2 is selected when address lines
A 14 =0 , A13 = 1.
So, for selection of given DAC A 15 =0 , A14 = 0 and A13 = 1.
Since the microprocessor has sixteen address lines then possible address range for Given
DAC can be as under,
So, the range of the address of the DAC can be from 2000 H to 3FFFH.
From the given options the address 3000H lies in the range of address of DAC.
Q.6 Ans (d)
rra
Memory Mapping By Dr. Ram Niwas, IES 73
To enable RAM its enable line should be high. Only one line of DEMUX with S 0 & S1 select
line is high depending on values of S0 & S1. Input of DEMUX is high only
When A 10 = 0, A11 = 1, A14 = 0, A15 = 0
For lowest Address all address lines of RAM should be ‘0’ and for highest address of RAM
all the address lines should be ‘1’.
Case-I: RAM # 1
RAM # 1 selected when S0 = A12 = 0 and S1 = A13 = 0
The range of address for RAM 1 is as under,
S1 S0
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 : 0800H
0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 : 0BFFH
So, range of RAM # 1 is 0800H to 0BFFH
Case – II: RAM # 2
RAM # 2 selected when S0 = A12 = 1 and S1 = A13 = 0
74 By Dr. Ram Niwas, IES Microprocessor 8085
S1 S0
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 :1800H
0 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 :1BFFH
Case-III: RAM # 3
RAM # 3 selected when S0 = A12 = 0 and S1 = A13 = 1
S1 S0
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 : 2800H
0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 : 2BFFH
Case-IV: RAM # 4
RAM # 4 selected when S0 = A12 = 1 and S1 = A13 = 1
S1 S0
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 : 3800H
0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 : 3BFFH
Q.7 Ans. (b)
The data will be transferred from data bus to output device only when the output port is
enabled. The output port is enable when ouput pin ‘2’ of the 3L to 8L decoder is low. The
output pin ‘2’ will be low if decoder is enabled with enable lines E 1 = 0 , E 2 = 0, E 3 = 1 and
inputs lines Io = 0, I1 = 1 & I2 = 0.
Thus for selection of output device, E 1 = IO/ M = 0, E 2 = WR = 0, Io = A13 = 0, I1 = A14=1
& I2 = A15 = 0. Here E 3 = A11A12 = 1 only if A111 = 0, A12=1. The address of the device can
be written as,
rra
Memory Mapping By Dr. Ram Niwas, IES 75
6
Instruction Set of 8085
and Programming
When the data transfer is with the memory or I/O device and address of memory or
I/O device is included in the instruction itself, the addressing mode is called direct
addressing mode. e.g. LDA 16 bit address, STA 16 bit address , IN 8bit address,
OUT 8bit address etc.
3. Indirect Addressing Mode
When the data transfer is with the memory or I/O device and address of memory or
I/O device is not included in the instruction rather it is indicated through a memory
pointer, the addressing mode is called indirect addressing mode. e.g. MOV M, R
; LDAX D etc.
4. Implicit or Implied Addressing Mode
When the instruction modifies the contents of accumulator without using any operand
the mode of addressing is called implicit or implied. In implied addressing mode, the
location of the operand is contained within the opcode.e.g. CMA, RLC, etc.
5. Immediate Addressing Mode
When 8 bit or 16 bit data is given in the instruction as operand the addressing mode
is called immediate addressing mode. e.g. ADI 8 bit data; SUI 8bit data; MVI R,
Instruction Set of 8085 135
8 bitdata; LXI Rp, 16 bit data.
Note: i. When ever there is letter ‘I’ at the end in a Mnemonics that indicates immediate
addressing mode.
ii. When one of the operand is letter ‘M’ that indicates the indirect addressing mode.
The format generally used to write an assembly language program is described in the next
section.
6.3.4 Program Format
Memory Machine Opcode Instruction Comments
Address Code Operand
(Hex) (Hex)
5000 0E MVI C,8AH ; Loads register C with data 8AH
5001 8A
5002 81 ADD C ; Adds (C) to (A)
5003 D3 OUT 03 ; Displays accumulator contents
5004 03 ; at port 03 H
5005 76 HLT ; Ends of the program
This program has five columns: Memory Address, Machine Code, Opcode, Operand, and
comments. Comments are separated by semicolon(;) from the mnemonics.
Machine Codes are the hexadecimal numbers (instruction codes) that are entered (or stored)
in the respective memory addresses through the hexadecimal keyboard of the microcomputer.
The monitor program, which is stored in Read-Only memory (ROM) of the microcomputer,
translates the Hex numbers into binary digits and stores the binary digits in the R/W memory.
The Key Monitor program is a set of instructions that continuously checks whether a key is
pressed and stores the binary equivalent of a pressed key in a memory location. W h e n
the power is turned on, the monitor program stored either in EPROM or ROM comes alive.
The RESET key clears the program counter, and the program counter holds the memory
address 0000H.
As soon as the RESET key is pushed, the program counter places the memory address
0000H on the address bus, the instruction at that location is fetched, and the execution of the
Key Monitor program begins. Therefore, the Key Monitor program is stored on page 00H.
4. MVI R, 8 bit data i. Copy the 8 bit data immediately to the register R
R A, B, C, D, E, H & L ii. 2-byte instruction
iii. Immediate addressing mode
iv. Two machine cycles (OP+MR) & 7T-states
v. No flag is affected
5. MVI M, 8 bit data i. Copy the 8 bit data immediately to the memory
M Memory address location whose address is stored in HL pair
stored in HL pair ii. 2-byte instruction.
iii. Immediate-indirect addressing mode.
iv. Three machine cycles (OP+MR+MW)&10
T-states.
v. No flag is affected.
6. LXI RP, 16 bit data i. Load the 16 bit data immediately in register
Rp BC, DE, HL & SP pair,Rp
ii. 3-byte instruction
iii. Immediate addressing mode
iv. Three machine cycles (OP+MR+MR)& 10
T-states
v. No flag is affected .
Note : While storing instruction in memory, the lower byte of 16 bit is stored at lower address
Instruction Set of 8085 139
and higher order byte is stored at higher address and at the time of execution the lower
order byte stored at lower address is first read into lower order register of register pair
Rp and higher order byte stored at higher address is read into higher order register.
8. STA 16 bit address i. Store the contents of ‘A’ at given 16 bit address
ii.3-byte instruction
Direct addressing mode
iii.
iv.Four machine cycles (OP+MR+MR+MW) &
13 T-states
v. No flag is affected
11. LHLD 16 bit address i. Load HL pair with the contents of given address
and next address. The contents of given address
are moved to L and contents of next address
are moved to H.
ii. 3 byte instruction
iii. Direct addressing mode
iv. Five machine cycles (OP+MR+MR+MR+MR)
& 16 T-states
v. No flag is affected
Ex.6.2 LHLD 3000 H , load register L with contents of 3000 H and register H with contents
of 3001 H.
12. SHLD 16 bit address i. Store HL pair at given 16 bit address and next
address. The contents of L are moved to given
and contents of H are moved to next address.
ii. 3 byte instruction
iii. Direct addressing mode
iv. Five machine cycles (OP+MR+MR+MW+MW)
& 16 T-states
v. No flag is affected
Ex.6.3 SHLD 3000 H , store the contents of L at 3000H and contents of register H at
3001H.
Ex 6.4 Consider the execution of the following instructions by a 8085 microprocessor :
LXI H, 01FFH
SHLD 2050H
What are the contents of memory locations 2050H and 2051H and the registers H and L
after execution of above instructions.
IES(EE,02)
Solution:
LXI H, 01FFH [ Load H = 01H, L = FFH]
SHLD, 2050H
After the execution of SHLD instruction, the contents of L are stored in 2050 and the
contents of H are stored in next memory location i.e. 2051. The content of H and L are
not altered
2050H = FF
2051H = 01
H = 01
L = FF
Note: The contents of lower order register are always stored at lower address and higher order
Instruction Set of 8085 141
register at higher address.
16. IN 8 bit port address i. Copy the contents of I/O mapped I/O device
connected at given 8 bit port address directly to
accumulator .
ii. 2-byte instruction
iii. Direct addressing mode
iv. Three machine cycles (OP+MR+IOR) & 10
T-states
v. No flag is affected
17. OUT 8 bit port address i. Copy the contents of accumulator directly to I/
O mapped I/O device connected at given 8 bit
port address
ii. 2-byte instruction
iii. Direct addressing mode
iv. Three machine cycles (OP+MR+IOW) & 10
T-states
v. No flag is affected
3. ADI 8bit data i. Add the 8 bit data immediately to A and store
the result in A
ii. 2-byte instruction
iii. Immediate addressing mode
iv. Two machine cycles (OP+MR) & 7T-states
v. All flags are affected
6. ACI 8 bit data i. Add the 8 bit data along with carry flag to
contents of A & store result in A
ii. 2-byte instruction
iii. Immediate addressing mode
iv. Two machine cycles (OP+MR) & 7T-states
v. All flags are affected
14. SBI 8 bit data i. Subtract the 8 bit data along with carry flag
from contents of A & store result in A
ii. 2-byte instruction
iii. Immediate addressing mode
iv. Two machine cycles (OP+MR) & 7T-states
v. All flags are affected
Ex6.7 In an 8085 system containing 8 KB of ROM and 8 KB of RAM, the ROM is selected when
A15 is 1. A13 and A14 are unused. The CPU executes the following program
Prog 1
MVI A, 00H
STA 8080 H
DCR A
STA C080H
RET
What are the content of memory location 8080 H after the execution of the RETURN
instruction?
GATE(IN,03)
Solution:
MVI A, 00 H ; Moves 00H to register A. So, A = 00H
STA 8080H ; Stores the contents of register A at memory location
8080H. So the contents of 8080H becomes 00H .
DCR A ; Decrements the contents of A by one. So the contents
Instruction Set of 8085 147
of A after decrement becomes FFH.
STA C080H ; Stores the contents of register A at memory location
C080H. So the contents of C080H becomes FFH .
RET ; Returns to the main program.
The content of memory location 8080H after the execution of the RETURN instruction is
00H.
Ex6.8 MVI B, 00H
MVI A, 1CH
DCR B
DAA
STA TEMP
HLT
What is the content of TEMP location after the execution of the above program ?
IAS(2008)
Solution:
MVI B, 00H ; Moves 00H to register B.
So, B = 00H
MVI A, 1CH ;
Moves 1C H to register A.
So, A = 1CH
DCR B ; Decrements the contents of B (i.e. 00H) by one. So,
B = FFH
DAA ; DAA instruction changes the binary values of contents
of accumulator to BCD. This instruction makes use of
status of CY and AC flags. It performs the operation
as follows,
I. If value of lower order four bits (D 3-D 0) in the
accumulator is greater than 9 or if AC flag is set ,
the instruction adds 0110H to low order four bits.
II. If value of higher order four bits (D7-D4) in the
accumulator is greater than 9 or if CY flag is set ,
the instruction adds 0110H to higher order four bits.
Here , lower order nibble of A is more than 9 but AC
flag is set by DCR B and upper nibble is less than 9 ,
therefore, DAA, adds 0110H to lower order nibble of
A to adjust binary result to Binary coded decimal.
A : 1C H = 0001 1100
+0110
0010 0010
So, A = 22H
STA TEMP ; Stores the contents of Accumulator at memory location
TEMP.
HLT ; Halts the execution of program.
Thus contents of TEMP are 22H.
148 Microprocessor 8085
6. ORI 8bit data i. 8 bit data is ORed with contents of A and result
Instruction Set of 8085 149
is stored in A
ii. 2-byte instruction
iii. Immediate addressing mode
iv. Two machine cycles (OP+MR) & 7T-states
v. All flags are affected. Both CY and AC flag
are reset.
CY 0
A=
1 0 0 1 0 0 1 0
A = 92H
After rotation :
CY 1
A=
0 0 1 0 0 1 0 0
A = 24H
MOV B,A ; Copies contents of accumulater A in register B.
Doubling the contents of register B before execution
of RAL instruction,
10010010 : 92 H
10010010 : 92 H
100100100 : 124 H
Thus result after execution of RAL is double of contents of register B before execution of
154 Microprocessor 8085
RAL . Hence this program doubles the contents of register B.
Ex.6.11 Read the following Assembly Language Program Segment of 8085 Microprocessor :
LXI H, 2501H
MOV A, L
ORI F0H
MOV L, A
MOV A,H
ANI F0H
MOV H, A
HLT
What are the contents of A, H and L registers after executing the above set of instructions
in sequence?
IES(EE,07)
Solution :
LXI H, 2501H ; Loads HL pair with 2501H. With H =25H and L = 01H
MOV A, L ; Moves the contents of L (i.e. 01H ) to A.
So, A = 01H
ORI F0H ; Contents of A are ORed with F0H and result is stored
in A.
A : 0000 0001
F0H : 1111 0000
1111 0001 = F1 H
So, A = F1 H
MOV L, A ; Moves the contents of A (i.e. F1H ) to L.
So, L = F1H
MOV A,H ; Moves the contents of H (i.e. 25H ) to A.
So, A = 25H
ANI F0 H ; Contents of A are ANDed with F0H and result is stored
in A.
A : 0010 0101
F0H : 1111 0000
0010 0000 = 20 H
So, A = 20 H
MOV H, A ; Moves the contents of A (i.e. 20H ) to H.
So, H = 20H
HLT ; Halts the execution of program.
So, after executing the above set of instructions in sequence the contents of A, H and L
registers are 20H, 20H and F1H respectively.
Ex. 6.12 The following program is written for an 8085 microprocessor to add two bytes located at
memory addresses 1FFEH and 1FFFH
LXI H, 1FFEH
MOV B, M
Instruction Set of 8085 155
INR L
MOV A,M
ADD B
INR L
MOV M, A
XRA A
What is memory location at which the result of addition is found on completion of the
execution of the above program.
GATE(EE,03)
Solutions:
LXI H, 1FFEH ; Loads HL pair with 1FFEH. So, H= 1FH and L = FEH
MOV B, M ; Moves the contents of memory location whose address
is stored in HL pair (i.e 1FFEH ) to register, B.
INR L ; Increases the contents of register L by one. So,
L = FFH.
MOV A,M ; Moves the contents of memory location whose address
is stored in HL pair (i.e 1FFFH ) to register, A.
ADD B ; Adds the contents of register B to register A and stores
the result in A. So the contents of memory location
1FFEH that are in register B are added to contents of
memory location 1FFFH that are in register A and sum
is stored in A only.
INR L ; Increases the contents of register L by one. So,L =
00H.
MOV M, A ; Moves the contents of accumulator A to memory
location whose address is stored in HL pair (i.e 1F00H).
XRA A ; The contents of A are Ex-ORed either with contents of
A itself and result is stored in A only. This instruction
will clear the accumulator and set the zero flag and
reset the carry flag.
So, the sum of two bytes stored at 1FFEH and 1FFFH will be stored at memory location
1F00H.
Ex.6.13 The following 8085 instructions are executed sequentially
XRA A
MOV L, A
MOV H, L
INX H
DAD H
What the contents of HL pair after execution of above program?
GATE(IN,04)
Solution:
XRA A ; Performs ExOR operation on the contents of A and
stores the r esult in A. The operation clears the
156 Microprocessor 8085
accumulator.
MOV L, A ; Copy the contents of A (i.e.00H) into L. So,L =00H
MOV H, L ; Copies the contents of L (i.e.00H) into H. So. H =00H
INX H ; Increment the contents of HL pair by one. So,
HL=0001H.
DAD H ; Adds the contents of HL pair (i.e. 0001H) to contents
of HL pair(i.e.0001H) and stores the result in HL pair.
HL: 0000 0000 0000 0001
HL :0000 0000 0000 0001
0000 0000 0000 0010
0 0 0 2
So, now contents of HL pair after the execution of program becomes 0002H.
Ex.6.14 The following program starts at location 0100H.
LXI SP, 000FH
LXI H, 0701H
MVI M, 00H
MVI A, 20H
SUB M
If in addition following code exists from 0109H onwards,
ORI 40H
ADD M
What will be the result in the accumulator after the last instruction is executed?
GATE(EC,05)
Solution:
0100H LXI SP, 000FH ; Initializes the stack pointer with 000F H address
0103H LXI H, 0701H : Loads HL pair with 0701H. So, H = 07H and L = 01H
0106H MVI M, 00H ; Moves 8 bit data 00H to memory location whose address
is stored in HL pair. So, 00H is moved to memory
location 0701H.
0108H MVI A, 20H ; Moves 8-bit data 20H to accumulator. So, A= 20H
So, the contents of A is 20H when program counter
reaches 0109H
010AH ORI 40H ; The contents of A(i.e.20H) are ORed with 8-bit data
40H.
20H : 00100000
40H : 01000000
01100000
A 60H
010CH ADD M ; Adds the contents of memory location, whose address
is stored in HL pair (i.e. 0701H) to the contents of
Instruction Set of 8085 157
A(i.e. 60H) and stores the result in A.
60 H : 01100000
00 H : 00000000
01100000
A 60H
The content of accumulator after the last instruction is executed is 60H
6.4.4 Machine Control Instructions
Ex.6.16 Consider the program given below, which transfers a block of data from one place in
memory to another :
MVI C, 0BH
Instruction Set of 8085 159
LXI H, 2400H
LXI D, 3400H
L1 : MOV A, M
STAX D
INR L
INR E
DCR C
JNZ LI
What is the total number of memory accesses (including instruction fetches) carried out ?
IES(EE,05)
Solution:
Mnemonic Operand No. of machine cycles/memory accesses
MVI C, 0BH 2
LXI H,2400H 3
LXI D, 3400H 3
L1 : MOV A, M 2
STAX D 2
INR L 1
INR E 1
DCR C 1
JNZ LI 3 or 2
Instructions before L1 needs 8 memory accesses and L1 to JNZ L1 requires 10 memory
accesses during each iteration upto last iteration but 9 machine cycles in last iteration when
Z = 0. The loop is executed 11 times till the contents of C becomes zero. So, the total number
of memory accesses are 8 + 10*10 + 9 = 117. JNZ requires 2 machine cycles when
condition is false. So total machine cycles will be 117.
Ex.6.17 Consider the following program intended to transfer a block of 5 bytes from A000H to
9000H:
START: LXI B, 9000H
LXI H, A000H
MVI C, 05H
LOOP: MOV A, M
STAX B
INX B
INX H
DCR C
JNZ LOOP
HLT
The above program will not work properly. Find out the reason.
IES(E&T,04)
Solution:
START: LXI B, 9000H
LXI H, A000H
MVI C, 05H
160 Microprocessor 8085
LOOP: MOV A, M
STAX B
INX B
INX H
DCR C
JNZ LOOP
HLT
The above program is intended to transfer a block of 5 bytes from A000H to 9000H, will not
work because the instruction INX B in the loop increases the BC pair by ‘1’ , the instruction
DCR C again restore same contents in BC pair as before execution of INX B. So, the
contents of register ‘C’ will never become Zero and instruction DCR C will not set the zero
flag and program will enter into infinite loop. The program will work properly if another
register such as D is used as counter instead of register C.
The correct program will as under,
START: LXI B, 9000H
LXI H, A000H
MVI D, 05H
LOOP: MOV A, M
STAX B
INX B
INX H
DCR D
JNZ LOOP
HLT
Ex.6.18 Consider the following assembly language program,
MVI B,87H
MOV A, B
START: JMP NEXT
MVI B, 00H
XRA B
OUT PORT 1
HLT
NEXT: XRA B
JP START
OUT PORT 2
HLT
What is result after execution of the above program in an 8085 microprocessor.
GATE(EC,02)
Solution:
The Sequence of execution of above program will be as under,
MVI B,87H ; Moves 87 H to B
MOV A, B ; Moves the contents of B (i.e. 87 H) to A. So, A = 87
H
Instruction Set of 8085 161
START:JMP NEXT ; Jumps to NEXT unconditionally
NEXT: XRA B ; Contents of B (i.e. 87H) are ExORed with contents of
A(i.e. 87H) and result is stored in A.
A B : 10000111
10000111
00000000
A = 00H
JP START ; Jumps to START if sign flag is reset. As XRA B in
previous step resets the sign flag so the program jumps
back to START.
START: JMP NEXT ; Jumps to NEXT unconditionally
NEXT: XRA B ; Contents of B (i.e. 87H) are ExORed with contents of
A(i.e. 00H) and result is stored in A.
A B : 00000000
10000111
10000111
A = 87H
As D7 bit of A is high so sign(S) flag is set.
JP START ; Jumps to START if sign flag is reset.
As XRA B in previous step sets the sign flag so the
program comes out of loop.
OUT PORT 2 ; Sends contents of A(i.e. 87H) to I/O device of PORT2
HLT ; Halts the execution of program.
Thus, program displays 87 H at port 2.
A 20 H and CY = 0
RLC ; Rotates contents of accumulator to left without carry
flag.
Before rotation:
CY 0
0 0 1 0 0 0 0 0
After rotation:
CY 0
0 1 0 0 0 0 0 0
A 40H and CY = 0
JNC BACK ; Jumps to BACK if CY = 0
HLT ; Halts the execution
After execution of RLC instruction 3 times CY flag will be set. So, the instruction NOP will
be executed three times in the given program.
Ex.6.22 8-bit signed integers in 2’s complement form are read into the accumulator of an 8085 micro-
processor from an I/O port using the following assembly language program segment with sym-
bolic addresses
BEGIN : IN PORT
RAL
JNC BEGIN
RAR
END: HLT
What is final outcome of above program?
GATE(IN,07)
Solution :
BEGIN : IN PORT ; Reads the data into accumulator from IO device
connected at PORT.
164 Microprocessor 8085
RAL ;Rotates the contents of accumulator to left through carry
flag.
JNC BEGIN ; Jumps to BEGIN if CY is not set.
RAR ; Rotates the contents of accumulator to right through
carry flag.
END: HLT ; Halts the execution of program.
When number read from IO device is negative number , the bit D7 of accumulator is ‘1’. So
the instruction RAL will set the carry flag and program execution will not jump to BEGIN
when it executes JNC BEGIN instruction as CY=1. So, the execution will continue with
RAR instruction and at end the program execution will halt after execution of HLT instruction.
GATE QUESTIONS
Q.1 The total number of memory accesses involved (inclusive of the op-code fetch) when an
8085 processor executes the instruction LDA 2003 is
(a) 1 (b) 2
(c) 3 (d) 4
GATE(EC.96)
Q.2 In an 8085 microprocessor, the instruction CMP B has been executed while the content of
the accumulator is less than that of register B. As a result
(a) Carry flag will be set but Zero flag will be reset
(b) Carry flag will be reset but Zero flag will be set
(c) Both Carry flag and Zero flag will be reset
(d) Both Carry flag and Zero flag will be set
GATE(EC,03)
Instruction Set of 8085 173
Q.3 The number of memory cycles required to execute the following 8085 instructions
(I) LDA 3000 H
(II) LXI D, F0F1 H
would be
(a) 2 for (I) and 2 for (II) (b) 4 for (I) and 3 for (II)
(c) 3 for (I) and 3 for (II) (d) 3 for (I) and 4 for (II)
GATE(EC,04)
Q.4 Consider the sequence of 8085 instructions given below.
LXI H, 9258
MOV A, M
CMA
MOV M, A
Which one of the following is performed by this sequence?
(a) Contents of location 9258 are moved to the accumulator
(b) Contents of location 9258 are compared with the contents of the accumulator
(c) Contents of location 8529 are complemented and stored in location 8529
(d) Contents of location 5892 are complemented and stored in location 5892
GATE(EC,04)
Q.5 If the HLT instruction of a 8085 microprocessor is executed,
(a) the microprocessor is disconnected from the system bus till the Reset is pressed
(b) the microprocessor enters into a Halt state and the buses are tri-stated
(c) the microprocessor halts execution of the program and returns to monitor
(d) the microprocessor reloads the program from the locations 0024 and 0025 H.
GATE(EE,92)
Q.6 The contents of the accumulator in an 8085 microprocessor is altered after the execution of
the instruction.
(a) CMPC (b) CPI 3 A
(c) ANI 5 C (d) ORA A
GATE(EE,94)
Q.7 In an 8085 microprocessor, after the execution of XRA A instruction
(a) the carry flag is set
(b) the accumulator contains FFH
(c) the zero flag is set
(d) the accumulator contents are shifted left by one bit
GATE(EE,95)
Q.8 The 8085 assembly language instruction that stores the contents of H and L registers into
the memory locations 2051 H and 2050H, respectively, is
(a) SPHL 2050H (b) SPHL 2051H
(c) SHLD 2050H (d) STAX 2050H
GATE(EE,05)
Q.9 In 8085 microprocessor, CY flag may be set by the instruction
(a) SUB (b) INX
(c) CMA (d) ANA
GATE(IN,01)
Q.10 For an 8085 microprocessor, the Stack Pointer (SP) and Program Counter (PC) registers
174 Microprocessor 8085
contain the number 2400H and F000H in Hex respectively. The contents of the register
after execution of the instruction CALL E000H would be
(a) PC : F003H SP : 2400H (b) PC : E000H SP : 2400H
(c) PC : E000H SP : 2401H (d) PC : E000H SP : 23FEH
GATE(IN,00)
Q.11 Find the correct match among the following pair in the context of an 8085 microprocessor.
(a) a-e, b-f, c-g, d-h (b) a-h, b-f, c-g, d-e
(c) a-h, b-g, c-f, d-e (d) a-f, b-h, c-g, d-e
GATE(IN,00)
Q.12 A memory mapped I / O device has an address of 00F0H. Which of the following 8085
instructions outputs the content of the accumulator to the I/O device?
(a) LXI H, 00F0H (b) LXI H, OOFOH
MOV M, A OUT M
(c) LXI H, 00F0H (d) LXI H, 00F0H
OUT F0H MOV A, M
GATE(IN,06)
Q.13 In an 8085 A microprocessor based system, it is desired to increment the contents of memory
location whose address is available in (D,E) register pair and store the result in same location.
The sequence of instructions is
(a) XCHG (b) XCHG
INR M INX H
(c) INX D (d) INR M
XCHG XCHG
GATE(EE,06)
Q.14 An 8085 assembly language program is given below.
Line 1 : MVI A, B5H
2 : MVI B, 0EH
3 : XRI 69H
4 : ADD B
5 : ANI 9BH
6 : CPI 9FH
7 : STA 3010H
8 : HLT
The contents of the accumulator just after execution of the ADD instruction in line 4 will be
(a) C3H (b) EAH
(c) DCH (d) 69H
GATE(EC,07)
Instruction Set of 8085 175
Q.15 In an 8085 microprocessor, the contents of the Accumulator, after the following instructions
are executed will become
XRA A
MVI B, F0H
SUB B
(a) 01 H (b) 0F H
(c) F0 H (d) 10 H
GATE(EE,09)
Q.16 The following is an assembly language program for 8085 microprocessors
Address Instruction Code Mnemonic
1000H 3E 06 MVI A,06H
1002H C6 70 ADI 70 H
1004H 32 07 10 STA 1007H
1007H AF XRA A
1008H 76 HLT
When this program halts, the accumulator contains
(a) 00H (b) 06H
(c) 70H (d) 76H
GATE(IN,09)
Q.17 For the 8085 assembly language program given below, the content of the accumulator after
the execution of the program is
3000 MVI A , 45 H
3002 MOV B, A
3003 STC
3004 CMC
3005 RAR
3006 XRA B
(a) 00H (b) 45H
(c) 67 H (d) E7H
GATE(EC,10)
Q.18 When a “CALL Addr” instruction is executed, the CPU carries out the following sequential
operations internally :
Note :–
(R) means content of register R
((R)) means content of memory location pointed to by R
PC means Program Counter
SP means Stack Pointer
(a) (SP) incremented (b) (PC) Addr
(PC) Addr ((SP)) (PC)
((SP)) (PC) (SP) incremented
(c) (PC) Addr (d) ((SP)) (PC)
(SP) incremented (SP) incremented
((SP)) (PC) (PC) Addr
GATE(EE,10)
Q.19 In an 8085 processor, the main program calls the subroutine SUB1 given below. When the
176 Microprocessor 8085
program returns to the main program after executing SUB1, the value in the accumulator is
Address Opcode Mnemonic
2000 3E 00 SUB1 : MVI A,00H
2002 CD 05 20 CALL SUB2
2005 3C SUB2 : INR A
2006 C9 RET
(a) 00 H (b) 01 H
(c) 02 H (d) 03 H
GATE(IN,10)
Q.20 The subroutine SBX given below is executed by an 8085 processor. The value in the
accumulator immediately after the execution of the subroutine will be.
SBX : MVI A, 99 H
ADI 11H
MOV C,A
RET
(a) 00 H (b) 11 H
(c) 99 H (d) AA H
GATE(IN,10)
Q.21 An 8085 assembly language program is given below. Assume that the carry flag is initially
unset. The contents of the accumulator after the execution of the program is
MVI A,07H
RLC
MOV B,A
RLC
RLC
ADD B
RRC
(a) 8CH (b) 64 H
(c) 23H (d) 15H
GATE(EC,11)
Q.22 A portion of the main program to call a subroutine SUB in an 8085 environment is given
below.
:
:
LXI D, DISP
LP : CALL SUB
:
:
It is desired that control be returned to LP + DISP + 3 when the RET instruction is executed
in the subroutine. The set of instruction that precede the RET instruction in the subroutine
are
(a) POP D (b) POP H
DAD H DAD D
PUSH D INX H
INX H
Instruction Set of 8085 177
INX H
PUSH H
(c) POP H (d) XTHL
DAD D INX D
PUSH H INX D
INX D
XTHL
GATE(EE,11)
Q.23 The contents (in Hexadecimal) of some of the memory locations in an 8085A based system
are given below:
Address Contents
26FF 00
26FF 01
2700 02
2701 23
2702 04
The contents of stack pointer (SP), program counter (PC) and (HL) are 2700H, 2100H and
0000H respectively. When the following sequence of instructions are executed.
2100 H: DAD SP
2101 H: PCHL
The contents of (SP) and (PC) at the end of execution will be
(a) (PC) = 2102H, (SP) = 2700H. (b) (PC) = 2700H, (SP) = 2700H.
(c) (PC) = 2800H, (SP) = 26FEH. (d) (PC) = 2A02H, (SP) = 2702H.
GATE(EE,08)
Q.24 An input device is interfaced with Intel 8085A microprocessor as memory mapped I/O. The
address of the device is 2500H. In order to input data from the device to accumulator, the
sequence of instructions will be
(a) LXI H, 2500H (b) LXI H,2500H
MOV A, M MOV M, A
(c) LHLD 2500H (d) LHLD 2500H
MOV A, M MOV M, A
GATE(EE,08)
Q.25 For 8085 microprocessor, the following program is executed.
MVI A, 05H;
MVI B, 05H;
PTR: ADD B;
DCR B;
JNZ PTR;
178 Microprocessor 8085
ADI 03H;
HLT;
At the end of program, accumulator contains
(A) 17 H (B) 20 H (C) 23 H (D) 05 H
GATE (EC, 13)
Q.26 In 8085 A microprocessor, the operation performed by the instruction LHLD 2100 H is
(a) (H) 21H, (L) 00H (b) (H) M(2100H), (L) M(2100H)
(c) (H) M(2101H), (L) M(2100H) (d) (H) 00H, (L) 21H
GATE (2014/EE-III/1 M)
Q.27 In an 8085 microprocessor, the following program is executed
2000 H XRA A
2001 H MVI B,04H
2003 H MVI A, 03H
2005 H RAR
2006 H DCR B
2007 H JNZ 2005
200 AH HLT
At the end of program, register A contains
(a) 60 H (b) 30 H
(c) 06 H (d) 03 H
GATE (2014/EE-II/2 M)
Q.28 In an 8085 microprocessor, the shift registers which store the result of an addition and the
overflow bit are, respectively
(a) B and F (b) A and F
(c) H and F (d) A and C
GATE (2015/EC-I/1 M)
Q.29 Which one of the following 8085 microprocessor programs correctly calculates the product
of two 8-bit numbers stored in registers B and C?
(a) MVI A, 00H (b) MVI A, 00H
JNZ LOOP CMP C
CMP C LOOP DCR B
LOOP DCR B JNZ LOOP
HLT HLT
After rotation:
So, content of A = 22 H
3006 XRA B ; Performs XOR operation between contents
of A & B and store the result in accumulator.
A :0 0 1 0 0 0 1 0
B:0 1 0 0 0 1 0 1
A B : 01 1 0 0 111
6 7
So, contents of A after execution of program are 67 H.
Q.18 Ans (d)
When a “CALL Addr” instruction is executed, the CPU carries out the following
sequential operations internally,
Step-I : Contents of Program counter are moved to on top of stack pointed by stack
pointer.
Step-II : The stack pointer is incremented.
Step-III : The address Addr is moved to program counter.
Note : In 8085 the contents of SP are decremented automatically by two when contents are moved
on top of stack because the stack pointer in 8085 is initiated with high address and data
storage begins from address lower than the address stored in SP. But in the given question
there is no such option.
Q.19 Ans. (c)
SUB1 : MVI A,00H ; Moves data 00 H to accumulator , A. So, contents of
A = 00H
CALL SUB2 ; Calls the subroutine SUB2
SUB2 : INR A ; Increases the contents of A by one.
RET ; Returns to calling subroutine.
Instruction Set of 8085 185
In the above program the instructions INR A is executed twice. Once by calling of SUB2
by Subroutine SUB1 and once by subroutine SUB1 itself. So, the contents of accumulator
are incremented twice. Therefore, the contents of A after returning from subroutine SUB1
will be 02H.
Q.20 Ans. (d)
SBX : MVI A, 99 H ; Moves data 99H to accumulator A.
ADI 11H ; Adds 11 H to contents of A(i.e. 99H).
A : 10011001
11H : 00010001
10101010
A = AA H and CY = 0
MOV C,A ; Moves contents of A to register C.
RET ; Returns to main program.
So, at the end of the program the contents of A are AA H.
Q.21 Ans(c)
Given contents of CY flag, CY = 0
MVI A,07H ; Moves data 07H to accumulator , A. So, A = 07H.
RLC ; Rotates contents of accumulator to left without carry flag.
Before rotation:
CY 0
0 0 0 0 0 1 1 1
After rotation:
CY 0
0 0 0 0 1 1 1 0
A = 0E Hand Cy = 0
MOV B,A ; Moves the contents of A(i.e. 0EH) to B . So B = 0EH.
RLC ; Rotates contents of accumulator to left without carry
flag.
Before rotation:
CY 0
0 0 0 0 1 1 1 0
After rotation:
CY 0
0 0 0 1 1 1 0 0
A = 1CHand Cy = 0
186 Microprocessor 8085
RLC ; Rotates contents of accumulator to left without carry
flag.
Before rotation:
CY 0
0 0 0 1 1 1 0 0
After rotation:
CY 0
0 0 1 1 1 0 0 0
A = 38Hand CY = 0
ADD B ; Adds the contents of B(i.e. 0EH) to the contents of
A(i.e. 38H).
0EH : 00001110
38H : 00111000
01000110
A = 46H and CY = 0
RRC ; Rotates contents of accumulator to right without carry
flag.
Before rotation:
CY 0
0 1 0 0 0 1 1 0
After rotation:
CY 0
0 0 1 0 0 0 1 1
A = 23 Hand CY = 0
Q.22 Ans (c)
Let,
Disp = 1000 H
L p = 2000 H
SUB = 5000 H
Main program :
:
:
LXI D, DISP
LP : CALL SUB
:
Instruction Set of 8085 187
:
Subroutine:
POP H
DAD D
PUSH H
RET
Program Description :
The segment of main programme given above first stores the 16 bit data (i.e. 1000 H) in DE
pair and than call the subroutins stored at add begining with SUB (i.e. 5000 H).
In last two machine cycles of CALL instruction the processor saves the contents of PC on
top of stack. So, before transferring the control of execution to subroutine the processor
saves the contents of program counter (i.e. LP + 3) on top of stack.
In sub routine during last three instruction preceding the RET instruction, the processor first
copies the contents of top of stack (i.e. 4 + 3) in HL pair, then adds contents of DE pair
(i.e. DISP) to contents of HL pair. After execustion of DAD D instruction the contents of
HL pair becomes LP + DISP + 3. Then processor saves the contents of HL pair on top of
stack. Now when RET instruction is executated the processor first copies the contents of
top of stack (i.e. LP + DISP + 3) in the program counter and then returns to main program.
So, program execution is transferred to LP + DISP + 3 after execution of RET instruction.
Main Program
.
.
LXI D, DISP ; Loads DE pair with 16-bit data ‘DISP’ . So, the contents
of DE pair are ‘DISP’
LP: CALL SUB ; Calls the subroutine stored at address ‘SUB’. During
last two machine cycles of CALL, the miroprocessor
saves address of next instruction (i.e. LP + 3) on top of
stack.
Subroutine SUB :
POP H ; Moves the contents of top of stack (i.e. LP + 3) in HL
pair. So contents of HL pair become LP + 3.
DAD D ; Adds contents of DE pair (i.e. DISP) to contents of
HL pair (i.e. LP + 3 ) and saves the result in HL pair.
So, contents of HL pair become LP + DISP + 3.
PUSH H ; Moves the contents of HL pair (i.e. LP + DISP + 3) on
top of stack.
RET ; Returns the execution to address stored on top of stack
(i.e. LP + DISP + 3). When return instruction is executed
the microprocessor moves contents of top of stack to
program counter. So the execution is transferred to the
address LP + DISP + 3.
Q.23 Ans.(b)
Given, SP =2700 H PC =2100 H and HL = 0000H
188 Microprocessor 8085
2100 H: DAD SP ; Adds the contents of SP pair(i.e. 2700H) to HL pair
(i.e. 0000H) and store result in HL pair.
HL :0000 0000 0000 0000
+SP :0010 0111 0000 0000
HL :0010 0111 0000 0000
2 7 0 0
After addition, HL = 2700 H
2101 H: PCHL ; Moves the contents of HL (i.e 2700H) pair to Program
Counter. So, PC = 2700 H.
The contents of (SP) and (PC) at the end of execution will be , PC = 2700H and SP = 2700H.
Q.24 Ans.(a)
Memory mapped I/O devices are indentified with 16-bit addresses just like a memory
location. Memory mapped I/O devices are accessed using same instructions which are used
to access memory locations. So, for reading the data into accumulator from I/O device
connected at 2500 H, following instructions can be used,
CY 0
0 0 0 0 0 0 1 1
After rotation:
CY 1
0 0 0 0 0 0 0 1
A = 01 H and CY = 1
2006 H DCR B ; Decreases the content of register B by one and all
flags are affected except carry flag. The contents of
B after decrement, B = 03 H. As contents of B are
non-zero so zero flag is reset. i.e. Z = 0.
2007 H JNZ 2005 ; Jump the execution to address 2005 if zero flag is not
set. Excecution jumbs of 2005 H till zero flag is set.
200AH HLT ; Halt the execution of program.
Here, the execution jumps back to address 2005 H thrice till the contents of B become zero.
Thus instruction RAR is executed four times and the contents of A are rotated to four times
through carry flag in total. In first run contents are A = 01H, CY = 1 and B = 03H as shown
above. In second run the contents become A = 80H, CY= 1 and B = 02H. During third run
A = C0H, CY= 0 and B = 01H. and in last and fourth run, A = 60H, CY= 0 and B = 00H and
Z = 1. Thus execution goes to HLT when zero flag is set.
Q.28 Ans. (b)
In an 8085 microprocessor, the shift registers which store the result of an addition and the
overflow bit are accumulator (A) and flag (F), respectively.
Q.29 Ans. (c)
Programme used for multiplication of two 8-bit numbers stored in registers B and C is,
MVI A, 00H ; Moves 00H to accumulator. So, A = 00H.
LOOP ADD C ; Adds the contents of register C to A.
DCR B ; Decrements the contents of B by one.
JNZ LOOP ; Jumps back to LOOP till the zero flag is set.
HLT ; Halts the execution.
In the above program first accumulator is loaded with 00H. The execution enters into loop
till the contents of B become zero. Thus the contents of C are added to A for a number of
times equal to number stored in B. Thus the results stored in A at the end of the program are
equal to the product of contents of B and C.
Q.30 Ans. (d)
MOV B, M ; Moves the contents of memory location M whose address is stored
in HL pair to register B.
PCHL ; Moves the contents of HL pair to the program counter
190 Microprocessor 8085
RNZ ; Return the execution to the calling subroutine if zero flag is not set.
SBI BEH ; Subtracts 8-bit data BEH from contents of accumulator along with
borrow.
Thus, the instruction which changes the content of the accumulator is SBI BEH.
Q.31 Ans. (c)
In an 8085 system, a PUSH operation requires more clock cycles than a POP operation
because the the stack pointer needs to be pre-decremented before writing registers in a
PUSH, whereas a POP operation uses the address already in the stack pointer.
Q.32 Ans. (d)
Given contents of accumulator and carry flag, A = A7 = 10100111; CY = 0
RLC ; Rotates contents of accumulator to left without carry
flag.
Before rotation:
CY 0
1 0 1 0 0 1 1 1
After rotation:
CY 1
0 1 0 0 1 1 1 1
A 4FH and CY = 1
Q.33 Ans.(b)
MVI A, 33H ; Moves 33 H to A
MVI B, 78H ; Moves 78 H to B
ADD B ; Adds the contents of B to A and stores result in A.
The contents of A after addition,
A : 00110011 or 33 H
+B : 01111000 or 78 H
________________
` A : 10101011 or AB H
CMA ; Complitments the contents of A. Contents of A after
complimenting becomes,
A : 01010100 or 54 H
ANI 32H ; Performs AND operation of 32 H with contents of A and
stores result in A.
A : 01010100 or 54 H
AND 00110010 or 32 H
________________
` A : 00010000 or 10 H
Thus the contents of A after execution of the fifth instruction is 10 H.
About the Author
Dr. Ram Niwas is from Indian Railways Services of Electrical Engineers. He
obtained BE degree in Electronics and Power Engineering from NIT(VRCE),
Nagpur in 1998, ME degree in Control and Instrumentation Engineering in 2003
from DCE, Delhi and PhD from IIT, Delhi in 2015. He worked with TATA
Infotech from January 2000 to June 2000. From August 2000 to
December 2001 he worked as lecturer in the Department of Electronics and
Communication Engineering in KIET, Ghaziabad. From December 2001 to August 2002 he
worked with BSNL as Junior Telecom Officer(JTO). From September 2002 onward he is
serving Indian Railways as IRSEE officer. He has vast experience of analytical approach to
competitive examinations. Author qualified IES examination twice in year 2001 and 2004. He
has published 13 research papers in international journals including 3 IEEE transactions and 4
IET journals.
DBS Publications
F-108, Katwaria Sarai, New Delhi-16
dbspublications17@gmail.com
i
To purchase this book you can contact at : dbspublications17@gmail.com