Maker Pro
Maker Pro

Call instruction in assembly language

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
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
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.
 
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
 

Harald Kapp

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