Connect with us

Call instruction in assembly language

Discussion in 'Microcontrollers, Programming and IoT' started by vead, Oct 5, 2013.

Scroll to continue with content
  1. vead

    vead

    473
    14
    Nov 27, 2011
    I want to create routine in assembly program but I don't have Idea when we need to create routine. why we need to create routine in program
     
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    Do you mean a subroutine?
     
  3. vead

    vead

    473
    14
    Nov 27, 2011
    yas how to create subroutine in program
     
  4. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    You provide insufficient information to provide any real answer at all.

    But now we know what you want to do, if you can tell us what language, or is assembly language, for what architecture and I'm sure we can provide you with an example of how.

    If your answer is "why?" then the answer is to do one or more of the following:

    1) To make the program more easily understood (by breaking it into modules)

    2) To separate out a routine used many times so that you only need to write it once (also makes the program smaller)

    3) To provide an interface (like an API) that can be called externally.
     
  5. vead

    vead

    473
    14
    Nov 27, 2011
    I want to program 8051 in assembly language
    example;
    turn on LED
    wait
    turn off led

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

    I want to ask when I need to use subroutine
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    9,906
    2,098
    Nov 17, 2011
    You don't "need" to.
    Subroutines have several functions:
    - make the code better readable. You give a good example yourself. Calling a "delay" subroutine makes it obvious what happens at this point in the program without having to read all the code that makes up the delay routine.
    - make the code better serviceable. By putting the code to perform a dedicated task into a subroutine, you only have to make changes to the subroutine if you need to change the code. You don't have to look for other parts of the code that perform this task.
    - save Memory. If you have code that is run many times within your program you would need Memory for every time the code is needed. A subroutine needs memory just once.
    - using subroutines is "good programming style".


    You can Google for more Information using "why use subroutines" as seach keywords.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-