LinkedIn Insight Summer 2018- Q.11 solution - Grad Plus

Summer 2018- Q.11 solution

Q.11) a) Explain addressing modes of 8051. [8M]

Solution:- An Addressing Mode is a way to locate a target Data, which is also called as Operand. The 8051 Family of Microcontrollers allows five types of Addressing Modes for addressing the Operands. They are:

  1. Immediate Addressing
  2. Register Addressing
  3. Direct Addressing
  4. Register – Indirect Addressing
  5. Indexed Addressing

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.

Example:  MOV A, #030H 

Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand indicates that it is a data and not the address of a Register.

Immediate Addressing is very fast as the data to be loaded is given in the instruction itself.

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 

Here, the 8-bit content of the Register R5 of Bank0 is moved to the Accumulator.

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.

Example:  MOV A, 47H 

Here, the data in the RAM location 47H is moved to the Accumulator.

Register Indirect Addressing

In the Indirect Addressing Mode or Register Indirect Addressing Mode, the address of the Operand is specified as the content of a Register. This will be clearer with an example.

Example:  MOV A, @R1 

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.

Indexed Addressing Mode

With Indexed Addressing Mode, the effective address of the Operand is the sum of a base register and an offset register. The Base Register can be either Data Pointer (DPTR) or Program Counter (PC) while the Offset register is the Accumulator (A).

In Indexed Addressing Mode, only MOVC and JMP instructions can be used. Indexed Addressing Mode is useful when retrieving data from look-up tables.

Example:  MOVC A, @A+DPTR 

Here, the address for the operand is the sum of contents of DPTR and Accumulator.


Q.11) b) Explain any three of the following instructions of 8051. [6M]
i) MULAB ii) SWAP iii) MOVX A, DPTR iv) SETB P 1.5 v) DJNZ R 3, label vi) DAA

Solution:- i)MULAB:-

Operation:MUL
Function:Multiply Accumulator by B
Syntax:MUL AB
InstructionsOpCodeBytesFlags
MUL AB0xA41C, OV

Description: Multiples the unsigned value of the Accumulator by the unsigned value of the “B” register. The least significant byte of the result is placed in the Accumulator and the most-significant-byte is placed in the “B” register.

The Carry Flag (C) is always cleared.

The Overflow Flag (OV) is set if the result is greater than 255 (if the most-significant byte is not zero), otherwise it is cleared.

ii) SWAP:-

Operation:SWAP
Function:Swap Accumulator Nibbles
Syntax:SWAP A
InstructionsOpCodeBytesFlags
SWAP A0xC41None

Description: SWAP swaps bits 0-3 of the Accumulator with bits 4-7 of the Accumulator. This instruction is identical to executing “RR A” or “RL A” four times.

iii) MOVX A, DPTR :-

Operation:MOVX
Function:Move Data To/From External Memory (XRAM)
Syntax:MOVX operand1,operand2
InstructionsOpCodeBytesFlags
MOVX @DPTR,A0xF01None
MOVX @R0,A0xF21None
MOVX @R1,A0xF31None
MOVX A,@DPTR0xE01None
MOVX A,@R00xE21None
MOVX A,@R10xE31None

Description: MOVX moves a byte to or from External Memory into or from the Accumulator.

If operand1 is @DPTR, the Accumulator is moved to the 16-bit External Memory address indicated by DPTR. This instruction uses both P0 (port 0) and P2 (port 2) to output the 16-bit address and data. If operand2 is DPTR then the byte is moved from External Memory into the Accumulator.

If operand1 is @R0 or @R1, the Accumulator is moved to the 8-bit External Memory address indicated by the specified Register. This instruction uses only P0 (port 0) to output the 8-bit address and data. P2 (port 2) is not affected. If operand2 is @R0 or @R1 then the byte is moved from External Memory into the Accumulator.

iv) SETB:-

Operation:SETB
Function:Set Bit
Syntax:SETB bit addr
InstructionsOpCodeBytesFlags
SETB C0xD31C
SETB bit addr0xD22None

Description: Sets the specified bit.

v) DJNZ R3, LABEL :-

Operation:DJNZ
Function:Decrement and Jump if Not Zero
Syntax:DJNZ register,reladdr
InstructionsOpCodeBytesFlags
DJNZ iram addr,reladdr0xD53None
DJNZ R0,reladdr0xD82None
DJNZ R1,reladdr0xD92None
DJNZ R2,reladdr0xDA2None
DJNZ R3,reladdr0xDB2None
DJNZ R4,reladdr0xDC2None
DJNZ R5,reladdr0xDD2None
DJNZ R6,reladdr0xDE2None
DJNZ R7,reladdr0xDF2None

Description: DJNZ decrements the value of register by 1. If the initial value of register is 0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new value of register is not 0 the program will branch to the address indicated by relative addr. If the new value of register is 0 program flow continues with the instruction following the DJNZ instruction.

vi) DAA:-

Operation:DA
Function:Decimal Adjust Accumulator
Syntax:DA A
InstructionsOpCodeBytesFlags
DA0xD41C

Description: DA adjusts the contents of the Accumulator to correspond to a BCD (Binary Coded Decimal) number after two BCD numbers have been added by the ADD or ADDC instruction. If the carry bit is set or if the value of bits 0-3 exceed 9, 0x06 is added to the accumulator. If the carry bit was set when the instruction began, or if 0x06 was added to the accumulator in the first step, 0x60 is added to the accumulator.

The Carry bit (C) is set if the resulting value is greater than 0x99, otherwise it is cleared.

Scroll to Top