The difference between ELAN MCU CALL and JMP

CALL subroutine call instruction:

      CALL is a call. After the called program has finished running, the last sentence of the call is returned by RET, which must be pushed onto the stack.


JMP is an unconditional jump and will not be pushed onto the stack.



When using JMP or CALL for program jump

If it is only limited to the range of the current page, there is no need to modify (A11, A10), and directly assign the target address to A9~A0, [For JMP instruction, this is fine; for CALL instruction, the next instruction to be executed PC+1 is pushed into the stack so that the program will return correctly after the CALL is executed.] If you need to jump to another page, you need to first set PS0 and PS1 of R3 and then load it into A11 and A10 of the PC.
If you use instructions to modify it directly The value of PC (R2), (such as: MOV R2 A or ADD R2 A or BC R2, 0), the lower 8 bits of the PC will be cleared, so the subsequent jumps will be limited to 256 of the page address.


The stack
EM78X has five levels of stacks, which follow the last-in first-out principle to implement up to five levels of nested calls. Usually the stack is used as follows: 
when CALL and interrupt response, PC+1 is pushed on the stack; 
when the subroutine or interrupt returns, execute RET , RETL (return parameters), the RETI (return from interrupt), the top of the stack (stack 1) playing back the program counter PC, and the value of the stack 2 of copy
shell to the stack 1, stack values onto the stack 3 is copied. 2, And so on.
It should be noted that the RET, RETL, and RETI instructions do not change the PS0~PS1 bits in R3 and return to the original page of the calling program. Therefore, when returning from a subroutine call that spreads across pages
, you must use instructions to restore the original in R3. The PS0 and PS1 values ​​of the

Guess you like

Origin blog.csdn.net/u013830926/article/details/72841496