0

In assembly language, is there a difference between a function and a procedure? I use them interchangeably but I'm not sure this is appropriate a professional environment.

  • 1
    Same difference as in other languages: a function has a return value and a procedure does not. They aren't fully interchangeable: you can call a function and ignore the return value but you can't call a procedure when you're expecting a return value. – Erik Eidt Aug 6 '16 at 4:37
  • I think they are a bit more interchangeable. Generally, you think of a function that will take and return values per the API calling convention and perform a small prologue to save the caller stack state, then perform its operation, clean up/restore any clobbered registers and exit. A procedure can be similar, here, but more of a function-light. you have more control of the calling convention and there generally isn't any formal requirement to save stack/base pointers before doing what needs doing, as a result of using the same call stack as the main code. – David C. Rankin Aug 6 '16 at 5:40
  • Note that opposed to most high-level languages, a "function" in assembly can return more than one value (i.e. all registers it changes can be considered return values if you don't consider that a procedure working on global variables) – tofro Sep 29 '16 at 9:30
0

In most (low level) assembly languages, neither the term "function" nor "procedure" exists, there are only subroutines, subroutine calls, and values returned through registers, the stack or other memory cells. In practice, it may be useful to think of these kind of subroutines in terms of functions or procedures, and talk about them using these terms, but there is probably no "standard" which defines one should only use the term "function", or "make always a clear distinction between procedures and function" in the context of assembly.

In particular assembly languages like this High Level Assembly, the abstraction of functions and procedures exist, and as you can see in the Wikipedia article, in that context both terms are used and distinguished, (at least when it is useful).

  • Microsoft Assembly Language (MASM) uses them both, iirc, and may be where he is getting those terms from. – Rob Aug 6 '16 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.