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