banner



Chegg Which Registers Hold The Stack Pointer, Return Address, And Program Counter?

The stack is a reserved area of the memory in RAM where we can store temporary information. Interestingly, the stack is a shared resource every bit information technology tin exist shared past the microprocessor and the programmer. The developer can use the stack to store information. And the microprocessor uses the stack to execute subroutines. The 8085 has a 16-flake register known equally the 'Stack Pointer.'

This annals's part is to hold the memory accost of the stack. This control is given to the programmer. The programmer can decide the starting accost of the stack by loading the address into the stack arrow register at the beginning of a program.

The stack works on the principle of First In Last Out. The retentivity location of the most contempo data entry on the stack is known as the Stack Tiptop.

How does a stack piece of work in associates language?

We use two master instructions to command the movement of data into a stack and from a stack. These two instructions are Push button and Popular.

Push – This is the education nosotros utilise to write information on the stack.
POP – This is the instruction we use to read information from the stack.

At that place are two methods to add data to the stack: Direct method and Indirect method

Directly method

In the straight method, the stack pointers address is loaded into the stack pointer annals direct.

LXI SP, 8000H LXI H, 1234H Push button H  Pop D HLT

Explanation of the lawmaking

LXI SP, 8000H – The accost of the stack arrow is set to 8000H by loading the number into the stack pointer annals.

LXI H, 1234H – Adjacent, nosotros add together a number to the HL pair. The most significant 2 bits will enter the H register. The least significant 2 bits volition enter the L annals.

PUSH H – The PUSH command will push the contents of the H register first to the stack. And so the contents of the 50 annals volition be sent to the stack. And so the new stack top will concur 34H.

POP D – The POP control volition remove the contents of the stack and shop them to the DE annals pair. The elevation of the stack clears first and enters the E annals. The new pinnacle of the stack is 12H at present. This one clears last and enters the D register. The contents of the DE register pair is now 1234H.

HLT – HLT indicates that the programme execution needs to terminate.

Indirect method

In the indirect method, the stack pointers address is loaded into the stack pointer register via some other register pair.

LXI H, 8000H SPHL LXI H, 1234H Push H  POP D HLT

Explanation of the lawmaking

LXI H, 8000H – The number that we wish to enter into the stack pointer, 8000H, is loaded into the HL pair register.

SPHL – This is a special command that nosotros tin can use to transfer data from HL pair to Stack pointer (SP). Now, the contents of the HL pair are in the SP.

LXI H, 1234H – Adjacent, we add together a number to the HL pair. The most significant ii bits volition enter the H annals. The least significant 2 bits volition enter the 50 register.

Button H – The PUSH command will push the contents of the H register first to the stack. And so the contents of the L register will exist sent to the stack. So the new stack superlative will hold 34H.

Popular D – The POP command will remove the contents of the stack and shop them to the DE annals pair. The acme of the stack clears first and enters the E register. The new peak of the stack is 12H now. This one clears final and enters the D register. The contents of the DE annals pair is now 1234H.

HLT – HLT indicates that the program execution needs to stop.

Both the methods can be shown diagrammatically with the following diagram.

working of a stack - direct and indirect method example

What is a Subroutine is assembly language?

A subroutine is a small program written separately from the main program to perform a particular task that yous may repeatedly require in the primary program. Essentially, the concept of a subroutine is that it is used to avoid the repetition of smaller programs.

Subroutines are written separately and are stored in a memory location that is different from the main program. You can telephone call a subroutine multiple times from the primary program using a simple Phone call education.

What are the conditional CALL statements in assembly linguistic communication?

Y'all can employ conditional Telephone call statements, also, according to your needs. These statements enter a subroutine only when a sure condition is met.

CC Call at address if cy (behave flag) = 1
CNC Call at address if cy (carry flag) = 0
CZ Call at address if ZF (zero flag) = ane
CNZ Telephone call at address if ZF (zip flag) = 0
CPE Call at address if PF (parity flag) = 1
CPO Telephone call at accost if PF (parity flag) = 0
CN Telephone call at address if SF (signed flag) = 1
CP Call at address if SF (signed flag) = 0

The subroutine can exist exited from using a return (RET) instruction.

What are the conditional return (RET) statements in assembly language?

Akin to the CALL educational activity, we have conditional RET statements likewise. These statements ensure that a subroutine is exited but when a sure condition is met.

RC Render from subroutine if cy (bear flag) = 1
RNC Render from subroutine if cy (acquit flag) = 0
RZ Return from subroutine if ZF (goose egg flag) = 1
RNZ Return from subroutine if ZF (zero flag) = 0
RPE Return from subroutine if PF (parity flag) = 1
RPO Return from subroutine if PF (parity flag) = 0
RN Return from subroutine if SF (signed flag) = one
RP Return from subroutine if SF (signed flag) = 0

After the completion of the subroutine, the main programme begins from the instruction immediately post-obit the Phone call instruction.

What are the advantages of using subroutines?

  • Subroutines avoid the repetition of instructions.
  • They give an aspect of modular programming to the unabridged programme.
  • Improves efficiency past reducing the size of the memory needed to store the program.

Chegg Which Registers Hold The Stack Pointer, Return Address, And Program Counter?,

Source: https://technobyte.org/stack-pointer-subroutines-8085/

Posted by: caldwellguttend1964.blogspot.com

0 Response to "Chegg Which Registers Hold The Stack Pointer, Return Address, And Program Counter?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel