| |||||||||||||
Technical Support On-Line Manuals Ax51 User's Guide | Program AddressesProgram addresses are absolute or relocatable expressions with the memory class CODE or ECODE. Typically, program addresses are used in jump and call instructions. For indirect jumps or calls, it is required to load a program address in a register or a jump table. The following jumps and calls are possible:
Example for all 8051 Variants
EXTRN CODE (my_function)
CSEG AT 3
JMP ext_int ; an interrupt vector
?PR?myintr SEGMENT CODE ; define a segment for program code
RSEG ?PR?myintr
ext_int: JB FLAG,flag_OK
INC my_var
flag_OK: CPL FLAG
RETI
?PR?myprog SEGMENT CODE INBLOCK ; a segment within a 2K block
RSEG ?PR?myprog
func1: CALL sub_func ; will generate ACALL
loop: CALL my_function ; external function -> LCALL
MOV A,my_var
JNZ loop
RET
sub_func: CLR FLAG
MOV R0,#20
loop1: CALL my_function
DJNZ R0,loop1
RET
Example with EJMP, ECALL for NXP 80C51MX
EXTRN ECODE:FAR (my_farfunc)
Reset EQU ECODE 0FF0000H ; Reset location on 251
?PR?my_seg SEGMENT ECODE ; define a SEGMENT of class EDATA
RSEG ?PR?my_seg
func1 PROC FAR ; far function called with ECALL
CALL func2 ; generates LCALL
CALL my_farfunc ; generates ECALL
JNB Flag,mylab
EJMP Reset
mylab: ERET
ENDP
func2 PROC NEAR
CALL my_farfunc ; generates ECALL
RET
ENDP
| ||||||||||||
| |||||||||||||