1. 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.
    Dismiss Notice

Call instruction in assembly

Discussion in '8051/8951' started by Parth86, Oct 5, 2013.

  1. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    516
    Likes:
    5
    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
     
  2. BeerBelly

    BeerBelly Member

    Joined:
    Sep 28, 2012
    Messages:
    262
    Likes:
    15
    Location:
    Northern California
    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.
     
  3. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE

    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...
     

Share This Page