Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Call instruction in assembly

Status
Not open for further replies.

Parth86

Member
I want to know about call instruction what actually they do in program or why we use call instruction in program
example:-
turn on LED
wait
turn off led

assembly program for 8051
SETB P0.1 ; turn on LED
ACALL DELAY ; wait (here why we use call instruction )
CLR P0.1 ; turn of led

another example
SETB P0.1 ; motor on
CALL FORWARD
ACALL DELAY ; wait
CALL REVERSE
CLR P0.1 ; motor off

why we use ACALL DELAY, ACALL FORWARD, ACALL REVERSE in above program
 
Call instructions are used when a (series of instructions), also known as a subroutine, are used multiple times.
Calling a subroutine can simplify debugging-If the subroutine is bug free it can be called over and over again and in future programs.
Using subroutines also makes programs easier to follow and understand.
 
Call and return depend on the actual processor implementation.

In a simple explanation:
Call would place the address of the next instruction on the stack and branch to the address of the routine. e.g. DELAY:

The RETURN get's the address off the stack and branches to it.
 
Looking at your question, it might look as if you are asking "Why we call"... It seems on a second read you are asking about "ACALL" as opposed to "CALL".

There are three call commands, each depends where the subroutine resides in program code.

ACALL is within 2048 program instructions away.. LCALL is when your subroutine is more than 2048 instructions away.
ACALL is Absolute CALL this uses absolute addressing. (11 bits +/- 1024 instructions)
LCALL is Long CALL this is for extended address is used. (16 bits +/- 32767 instructions)

If it doesn't matter to you how your program is optimized then you can just call CALL This is the generic call and I think it defaults to LCALL.

The same applies to JMP... AJMP, SJMP and LJMP.. However!! SJMP is only 8 its ( 255 instructions +/- 128) and is used for optimizing still further...
 
Status
Not open for further replies.

Latest threads

Back
Top