Types of Addressing Modes
Types of Addressing Modes
Types of Addressing Modes
MICROPROCESSOR:
8085
Types of addressing modes –
In 8085 microprocessor there are 5 types of addressing modes:
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts
for SDE interviews with the CS Theory Course at a student-friendly price and become
industry ready.
In immediate addressing mode the source operand is always data. If the data is
8-bit, then the instruction will be of 2 bytes, if the data is of 16-bit then the
instruction will be of 3 bytes.
Examples:
LXI H 3050 (load the H-L pair with the operand 3050H immediately)
Examples:
ADD B (add contents of registers A and B and store the result in register A)
Examples:
LHLD address (load contents of 16-bit memory location into H-L register pair)
Examples:
MOV A, M (move the contents of the memory location pointed by the H-L pair
to the accumulator)
LXIH 9570 (load immediate the H-L pair with the address of the location 9570)
Examples:
CMA (finds and stores the 1’s complement of the contents of accumulator A in
A)
Example
MOV CX, 4929 H, ADD AX, 2387 H, MOV AL, FFH
Example
MOV CX, AX ; copies the contents of the 16-bit AX register into
; the 16-bit CX register),
ADD BX, AX
Example
MOV AX, [1592H], MOV AL, [0300H]
Example
MOV AX, [BX] ; Suppose the register BX contains 4895H, then the
contents
; 4895H are moved to AX
ADD CX, {BX}
Example
MOV DX, [BX+04], ADD CL, [BX+08]
Indexed addressing mode
In this addressing mode, the operands offset address is found by adding the
contents of SI or DI register and 8-bit/16-bit displacements.
Example
MOV BX, [SI+16], ADD AL, [DI+16]
Example
ADD CX, [AX+SI], MOV AX, [AX+DI]
Example
MOV AX, [BX+DI+08], ADD CX, [BX+SI+16]
MICROCONTROLLER:
8081
Immediate Addressing
In Immediate Addressing mode, the operand, which follows the Opcode, is a
constant data of either 8 or 16 bits. The name Immediate Addressing came from
the fact that the constant data to be stored in the memory immediately follows
the Opcode.
The constant value to be stored is specified in the instruction itself rather than
taking from a register. The destination register to which the constant data must
be copied should be the same size as the operand mentioned in the instruction.
Register Addressing
In the 8051 Microcontroller Memory Organization Tutorial, we have seen the
organization of RAM and four banks of Working Registers with eight Registers
in each bank.
In Register Addressing mode, one of the eight registers (R0 – R7) is specified as
Operand in the Instruction.
It is important to select the appropriate Bank with the help of PSW Register. Let
us see a example of Register Addressing assuming that Bank0 is selected.
Example: MOV A, R5
Direct Addressing
In Direct Addressing Mode, the address of the data is specified as the Operand
in the instruction. Using Direct Addressing Mode, we can access any register or
on-chip variable. This includes general purpose RAM, SFRs, I/O Ports, Control
registers.
Here, the data in the RAM location 47H is moved to the Accumulator.
The @ symbol indicates that the addressing mode is indirect. If the contents of
R1 is 56H, for example, then the operand is in the internal RAM location 56H.
If the contents of the RAM location 56H is 24H, then 24H is moved into
accumulator.
Only R0 and R1 are allowed in Indirect Addressing Mode. These register in the
indirect addressing mode are called as Pointer registers.
In Indexed Addressing Mode, only MOVC and JMP instructions can be used.
Indexed Addressing Mode is useful when retrieving data from look-up tables.
Here, the address for the operand is the sum of contents of DPTR and
Accumulator.
INTERRUPTS
Interrupts in 8085
Interrupts are the signals generated by the external devices to
request the microprocessor to perform a task. There are 5 interrupt
signals, i.e. TRAP, RST 7.5, RST 6.5, RST 5.5, and INTR.
Interrupt are classified into following groups based on their
parameter −
Vector interrupt − In this type of interrupt, the interrupt
address is known to the processor. For example: RST7.5,
RST6.5, RST5.5, TRAP.
Non-Vector interrupt − In this type of interrupt, the interrupt
address is not known to the processor so, the interrupt
address needs to be sent externally by the device to perform
interrupts. For example: INTR.
Maskable interrupt − In this type of interrupt, we can disable
the interrupt by writing some instructions into the
program. For example: RST7.5, RST6.5, RST5.5.
Non-Maskable interrupt − In this type of interrupt, we cannot
disable the interrupt by writing some instructions into the
program. For example: TRAP.
Software interrupt − In this type of interrupt, the programmer
has to add the instructions into the program to execute the
interrupt. There are 8 software interrupts in 8085, i.e. RST0,
RST1, RST2, RST3, RST4, RST5, RST6, and RST7.
Hardware interrupt − There are 5 interrupt pins in 8085 used
as hardware interrupts, i.e. TRAP, RST7.5, RST6.5, RST5.5,
INTA.
8086 INTERRUPTS
Hardware Interrupts
Hardware interrupt is caused by any peripheral device by sending a signal through
a specified pin to the microprocessor.
The 8086 has two hardware interrupt pins, i.e. NMI and INTR. NMI is a non-
maskable interrupt and INTR is a maskable interrupt having lower priority. One
more interrupt pin associated is INTA called interrupt acknowledge.
NMI
It is a single non-maskable interrupt pin (NMI) having higher priority than the
maskable interrupt request pin (INTR)and it is of type 2 interrupt.
When this interrupt is activated, these actions take place −
Completes the current instruction that is in progress.
Pushes the Flag register values on to the stack.
Pushes the CS (code segment) value and IP (instruction pointer) value of the
return address on to the stack.
IP is loaded from the contents of the word location 00008H.
CS is loaded from the contents of the next word location 0000AH.
Interrupt flag and trap flag are reset to 0.
INTR
The INTR is a maskable interrupt because the microprocessor will be interrupted
only if interrupts are enabled using set interrupt flag instruction. It should not be
enabled using clear interrupt Flag instruction.
The INTR interrupt is activated by an I/O port. If the interrupt is enabled and NMI is
disabled, then the microprocessor first completes the current execution and sends
‘0’ on INTA pin twice. The first ‘0’ means INTA informs the external device to get
ready and during the second ‘0’ the microprocessor receives the 8 bit, say X, from
the programmable interrupt controller.
These actions are taken by the microprocessor −
First completes the current instruction.
Activates INTA output and receives the interrupt type, say X.
Flag register value, CS value of the return address and IP value of the return
address are pushed on to the stack.
IP value is loaded from the contents of word location X × 4
CS is loaded from the contents of the next word location.
Interrupt flag and trap flag is reset to 0
Software Interrupts
8051- INTERRRUPTS
Interrupts are the events that temporarily suspend the main program, pass the
control to the external sources and execute their task. It then passes the control
to the main program where it had left off.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt
can be enabled or disabled by setting bits of the IE register and the whole
interrupt system can be disabled by clearing the EA bit of the same register.
The 8051 controller has six hardware interrupts of which five are available to
the programmer. These are as follows:
1. RESET interrupt – This is also known as Power on Reset (POR). When the
RESET interrupt is received, the controller restarts executing code from 0000H
location. This is an interrupt which is not available to or, better to say, need not
be available to the programmer.
2. Timer interrupts – Each Timer is associated with a Timer interrupt. A timer
interrupt notifies the microcontroller that the corresponding Timer has finished
counting.
3. External interrupts – There are two external interrupts EX0 and EX1 to
serve external devices. Both these interrupts are active low. In AT89C51, P3.2
(INT0) and P3.3 (INT1) pins are available for external interrupts 0 and 1
respectively. An external interrupt notifies the microcontroller that an external
device needs its service.
4. Serial interrupt – This interrupt is used for serial communication. When
enabled, it notifies the controller whether a byte has been received or
transmitted.
Example:
MVI A 30 (load 30H in register A)
MVI B 40 (load 40H in register B)
SUB B (A = A – B)
These set of instructions will set the sign flag to 1 as 30 – 40 is a
negative number.
Example:
MVI A 10 (load 10H in register A)
SUB A (A = A – A)
These set of instructions will set the zero flag to 1 as 10H – 10H is
00H
Example:
Example:
Example:
flag 8086
Status Flag Registers:
1. Overflow Flag (OF):
Zero Flag (ZF) is set to 1 when result is zero. For non-zero result this
flag is set to 0.
4. Auxiliary Flag (AF):
Parity Flag is set to 1 when there is even number of one bits in result,
and to 0 when there is odd number of one bits.
CY, the carry flag − This carry flag is set (1) whenever there is
a carry out from the D7 bit. It is affected after an 8-bit addition
or subtraction operation. It can also be reset to 1 or 0 directly by
an instruction such as "SETB C" and "CLR C" where "SETB"
stands for set bit carry and "CLR" stands for clear carry.
AC, auxiliary carry flag − If there is a carry from D3 and D4
during an ADD or SUB operation, the AC bit is set; otherwise,
it is cleared. It is used for the instruction to perform binary
coded decimal arithmetic.
P, the parity flag − The parity flag represents the number of 1's
in the accumulator register only. If the A register contains odd
number of 1's, then P = 1; and for even number of 1's, P = 0.
OV, the overflow flag − This flag is set whenever the result of
a signed number operation is too large causing the high-order
bit to overflow into the sign bit. It is used only to detect errors
in signed arithmetic operations.