How do branch instructions work




















So suppose the stack had the following values on it already before the JSR instruction:. A RET instruction would load the Program Counter to load , and pop a value from the stack, leaving the stack as. If another RET instruction was executed, the program counter would be loaded with , and the stack would just contain 03E. A stack is normally a part of the ordinary memory; CPUs use a register called a stack pointer to hold the address of the top of the stack; and every time to write to the stack, you change the address by one.

The clever thing about this stack system is that you can call subroutines - special bits of code - which can themselves call subroutines.

Consider the following example as follows:. This illustrates one important feature of the use of calling procedures; it allows the writing of clear and understandable code. It is clear that in this program, after the initialisation process, the program enters and endless loop, where it repeatedly reads and displays data.

The stack allows procedures to be "nested" that is: a procedure could call a procedure, which could call a procedure, etc They allow the writing of clear and structured code, which is easy to understand, and easy to modify: e.

Procedures also allow the use of the same code in different parts of the program. For example, you may have written a delay procedure, which causes a delay whose length is proportional to the value of r0. Jump Instructions — The jump instruction transfers the program sequence to the memory address given in the operand based on the specified flag.

Call Instructions — The call instruction transfers the program sequence to the memory address given in the operand. Before transferring, the address of the next instruction after CALL is pushed onto the stack. Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Previous Data transfer instructions in microprocessor.



0コメント

  • 1000 / 1000