SECTION IV - STACK DIRECT AND REGISTER INDIRECT ADDRESSING MODE IN 8051

SECTION IV - STACK DIRECT AND REGISTER INDIRECT ADDRESSING MODE IN 8051

Stack and Direct Addressing Mode:

The direct addressing mode is allowed for pushing onto the stack. The instruction "PUSH A" is invalid. Pushing the accumulator onto the stack must be coded as "PUSH 0E0H". 0E0H is the address of the register accumulator A. Pushing R2 of 'Bank 0' is coded as "PSUH 02". Direct addressing mode must also be used for POP instruction as well. e.g; "POP 03" will pop the top of the stack into into R3 of 'Bank 0'.

Example # 1:

Lets show the code to PUSH R1,R2 and A onto the stack and then POP them back into R3,R4 and B, where B=register A, R3=R2, R4=R1.

PUSH 01;PUSH R1 onto stack
PUSH 02;PUSH R2 onto stack
PUSH 0E0H;PUSH register A onto stack
POP 0F0H;POP top of stack into register B, now register B = register A
POP 03POP top of stack into register R4, now R3 = R2
POP 04POP top of stack into register R5, now R4 = R1

Register and Indirect Addressing Mode:

The register is used as a pointer in register indirect addressing mode. The registers R0 and R1 only is used for this purpose, if data is inside the CPU. The registers R2, R3, R4, R5, R6, R7 cannot be used for indirect addressing mode to hold the address of an operand located in random access memory RAM. The registers must be preceded by the " @ " sign.

MOV A, @R0;Move contents of RAM location whose address is held by R0 into A
MOV @R1, B;Move contents of B into RAM location whose address is held by R1

In the absence of "@" sign, MOV will be interpreted as an instruction moving the contents of register R0 to register A. Instead of the contents of memory location pointed to by R0.

Example # 2:

Lets write a program to copy the value AAH into RAM memory locations 30H to 35H using (1) Direct addressing mode (2) Register indirect addressing mode without a loop (3) with a Loop

(1) Direct Addressing Mode:

MOV A, #AAH;Load accumulator with value AAH
MOV 30H, A;Copy accumulator A to RAM location 30H
MOV 31H, A;Copy accumulator A to RAM location 30H
MOV 32H, A;Copy accumulator A to RAM location 30H
MOV 33H, A;Copy accumulator A to RAM location 30H
MOV 34H, A;Copy accumulator A to RAM location 30H

(2) Register Indirect Addressing Mode without Loop:

MOV A, #AAH;Load accumulator with value AAH
MOV R0, #30H;Load the pointer R0=30H, RAM address value
MOV @R0, A ;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 30H
INC R0;Increment Pointer R0 i.e R0=30H+1=31H now
MOV @R0, A;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 31H
INC R0;Increment Pointer R0 i.e R0=31H+1=32H now
MOV @R0, A;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 32H
INC R0;Increment Pointer R0 i.e R0=32H+1=33H now
MOV @R0, A;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 33H
INC R0;Increment Pointer R0 i.e R0=33H+1=34H now
MOV @R0, A;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 34H

(3) Register Indirect Addressing Mode With Loop:

MOV A, #AAH;Load accumulator with value AAH
MOV R0, #30H;Load pointer 30H as RAM address value
MOV R2, #05; Load the counter, R2=5
AGAIN: MOV @R0, A;Copy A to RAM location R0 points to i.e Copy AAH to RAM location 30H
INC R0;Increment R0 pointer
DJNZ R2, AGAIN;Loop until the counter R0 = 0

 

More From Iamtechnical.com

Advertisement: