0% found this document useful (0 votes)
10 views

Call Instruction

The document discusses call instructions and stack usage in 8051 assembly language. It provides examples of using LCALL and ACALL to call subroutines from a main program. LCALL allows targeting addresses anywhere in 64k memory, while ACALL can save program space. PUSH and POP are used to preserve register values across subroutine calls. Subroutines can be tested separately and combined with the main program later. Finally, it discusses machine cycle times for different 8051 chips based on the crystal oscillator frequency.

Uploaded by

mostafa hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Call Instruction

The document discusses call instructions and stack usage in 8051 assembly language. It provides examples of using LCALL and ACALL to call subroutines from a main program. LCALL allows targeting addresses anywhere in 64k memory, while ACALL can save program space. PUSH and POP are used to preserve register values across subroutine calls. Subroutines can be tested separately and combined with the main program later. Finally, it discusses machine cycle times for different 8051 chips based on the crystal oscillator frequency.

Uploaded by

mostafa hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CALL INSTRUCTION

 Call Instruction & Stack:


001 0000 ORG 0
002 0000 7455 BACK: MOV A,#55H ;load A with 55H
003 0002 F590 MOV P1,A ;send 55H to p1
004 0004 120300 LCALL DELAY ;time delay
005 0007 74AA MOV A,#0AAH ;load A with AAH
006 0009 F590 MOV P1,A ;send AAH to p1
Stack frame after the first LCALL
007 000B 120300 LCALL DELAY
008 000E 80F0 SJMP BACK ;keep doing this
009 0010 Low byte goes first & high byte is last
010 0010 ;-------this is the delay subroutine------
011 0300 ORG 300H 0A

012 0300 DELAY: 09 00

013 0300 7DFF MOV R5,#0FFH ;R5=255 08 07

014 0302 DDFE AGAIN: DJNZ R5,AGAIN ;stay here SP = 09


015 0304 22 RET ;return to caller
016 0305 END ;end of asm file
CALL INSTRUCTION
 Use PUSH/POP in subroutine:
01 0000 ORG 0
02 0000 7455 BACK: MOV A,#55H ;load A with 55H
03 0002 F590 MOV P1,A ;send 55H to p1
04 0004 7C99 MOV R4,#99H
05 0006 7D67 MOV R5,#67H
06 0008 120300 LCALL DELAY ;time delay
07 000B 74AA MOV A,#0AAH ;load A with AA
08 000D F590 MOV P1,A ;send AAH to p1
09 000F 120300 LCALL DELAY
10 0012 80EC SJMP BACK ;keeping doing
this
11 0014 ;-------this is the delay subroutine------
CALL INSTRUCTION
12 0300 ORG 300H
13 0300 C004 DELAY: PUSH 4 ;push R4
Normally, the number of
14 0302 C005 PUSH 5 ;push R5 PUSH & POP instruction
15 0304 7CFF MOV R4, #0FFH ;R4=FFH must always match in any
subroutine
16 0306 7DFF NEXT: MOV R5, #0FFH ;R5=FFH
17 0308 DDFE AGAIN: DJNZ R5, AGAIN
18 030A DCFA DJNZ R4, NEXT
19 030C D005 POP 5 ;POP into R5
20 030E D004 POP 4 ;POP into R4
21 0310 22 RET ;return to caller
22 0311 END ;end of asm file
CALL INSTRUCTION
 Calling Subroutine:
;MAIN program calling subroutines It is common to have
ORG 0 one main program &
MAIN: LCALL SUBR_1 many subroutine that
LCALL SUBR_2 are called from the
main program
LCALL SUBR_3
HERE: SJMP HERE
;-----------end of MAIN
SUBR_1: ...
This allows you to to
make each subroutine
...
into a separate module
RET - Each module can be
;-----------end of subroutine1 tested separately &
SUBR_2: ... then brought
... together with main
RET
program.
- In a large program,
;-----------end of subroutine2
the module can be
SUBR_3: ... assigned to different
... programmers.
RET
;-----------end of subroutine3
END ;end of the asm file
CALL INSTRUCTION

ACALL and LCALL:

 The only difference between ACALL and LCALL is


 The target address for LCALL can be anywhere within the 64K byte address
 The use of ACALL instead of LCALL can save a number of bytes of program ROM
space
CALL INSTRUCTION
 ACALL (cont’):
ORG 0
BACK: MOV A,#55H ;load A with 55H
MOV P1,A ;send 55H to port 1
LCALL DELAY ;time delay
MOV A,#0AAH ;load A with AA (in hex)
MOV P1,A ;send AAH to port 1
LCALL DELAY
SJMP BACK ;keep doing this indefinitely
...
END ;end of asm file

A rewritten program which is more efficiently

ORG 0
MOV A,#55H ;load A with 55H
BACK: MOV P1,A ;send 55H to port 1
ACALL DELAY ;time delay
CPL A ;complement reg A
SJMP BACK ;keep doing this indefinitely
...
END ;end of asm file
TIME DELAY FOR VARIOUS 8051 CHIPS

 CPU executing an instruction takes a number of clock cycles.


 These are referred as to as machine cycles.

 The length of machine cycle depends on the frequency of the crystal oscillator
connected to 8051.

 In original 8051, one machine cycle lasts 12 oscillator periods.

Find the period of the machine cycle for 11.0592 MHz crystal
frequency
Solution:
11.0592/12 = 921.6 kHz;
machine cycle is 1/921.6 kHz = 1.085μs

You might also like