ASM2 - Documentation
  • 📚ASM2 - Documentation
  • Registers
  • Address Registers
  • Instructions
    • DISP
    • END
    • MOV
    • RET
  • Operators
    • ADD
    • SUB
    • MUL
    • DIV
  • Functions
  • Subroutines
  • Jump
    • Conditional Jump
      • Jump Equal (JE)
      • Jump Not Equal (JNE)
      • Jump Greater (JG)
      • Jump Greater or Equal (JGE)
      • Jump Less (JL)
      • Jump Less or Equal (JLE)
    • Unconditional Jump
Powered by GitBook
On this page

Functions

Functions in ASM2 assembly language are blocks of code designed to perform specific tasks, facilitating modular and structured programming. They provide a way to encapsulate code for specific operations, enhancing readability and reusability.

Naming Convention:

  • CamelCase: Function names must use camelCase.

  • No Initial Numbers: Cannot start with a number.

  • Not Solely Numeric: Cannot be just a number.

  • No Special Characters: Cannot contain special characters.

  • No Underscores at Start/End: Cannot start or end with _.

General Structure:

assemblyCopy .functionName
    ; Context and description
    ; OPERANDS Setup: DESTINATION, SOURCE

    ; Function body (code performing the task)
    
    ; Return value (if any)
    
END

Example:

assemblyCopy .addNumbers
    ; Adds two numbers and returns the result
    ; Input: OPERANDS Setup: DESTINATION, SOURCE

    ADD DESTINATION, SOURCE
    
    RET
END

Key Points:

  • Modularity: Encapsulates specific tasks, making the code modular.

  • Reuse: Allows code to be reused throughout the program.

  • Clarity: Provides clear structure for specific operations.

  • END Instruction: Marks the end of the function, returning control to the calling code.

PreviousDIVNextSubroutines

Last updated 1 year ago