This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:papc:chapter_6_12 [2025/11/14 11:52] – [Operators] ktokarz | en:multiasm:papc:chapter_6_12 [2025/11/17 08:33] (current) – [Constants] ktokarz | ||
|---|---|---|---|
| Line 63: | Line 63: | ||
| The operators which can be used in numeric expressions are | The operators which can be used in numeric expressions are | ||
| - | * *****, **/** - multiplication and division | + | * ** * **, ** / ** - multiplication and division |
| * **MOD** | * **MOD** | ||
| * **SHL**, **SHR** | * **SHL**, **SHR** | ||
| Line 69: | Line 69: | ||
| The operators which can be used in numeric and address expressions are | The operators which can be used in numeric and address expressions are | ||
| - | * **+**, **-** - addition, subtraction | + | * ** + **, ** - ** - addition, subtraction |
| * **HIGH**, **LOW** | * **HIGH**, **LOW** | ||
| * **HIGHWORD**, | * **HIGHWORD**, | ||
| * **HIGH32**, **LOW32** | * **HIGH32**, **LOW32** | ||
| - | + | The type operators | |
| - | + | ||
| - | + | ||
| - | The type operators determine the number of bytes in a single variable, the number of elements in a data array, or the size of a whole data array {{ref> | + | |
| <table masmtypeoperators> | <table masmtypeoperators> | ||
| < | < | ||
| Line 125: | Line 122: | ||
| - | ===== Important | + | ===== Selected |
| The **ORG** directive sets the location counter to the specified value x. It is used to align the parts of the program to a specific address. | The **ORG** directive sets the location counter to the specified value x. It is used to align the parts of the program to a specific address. | ||
| Line 136: | Line 133: | ||
| The **LABEL** directive creates a new label by assigning the current location-counter value and the given type to the defined name. Usually in a program, the **:** (colon) sign is used for label definition, but the **LABEL** directive enables specifying the type of element which the label points to. | The **LABEL** directive creates a new label by assigning the current location-counter value and the given type to the defined name. Usually in a program, the **:** (colon) sign is used for label definition, but the **LABEL** directive enables specifying the type of element which the label points to. | ||
| + | ===== Data definition directives ===== | ||
| There is a set of directives for defining variables. They enable the assignment of a name to a variable and the specification of its type. They are summarised in a table | There is a set of directives for defining variables. They enable the assignment of a name to a variable and the specification of its type. They are summarised in a table | ||
| {{ref> | {{ref> | ||
| Line 192: | Line 190: | ||
| inc RBX | inc RBX | ||
| loop clear | loop clear | ||
| + | </ | ||
| + | |||
| + | ===== Constants ===== | ||
| + | Constants in an assembler program define the name for the value that can't be changed during normal program execution. It is the assembly-time assignment of the value and its name. Although their name suggests that their value can't be altered, it is true at the program run-time. Some forms of constants can be modified during assembly time. Usually, constants are used to self-document the code, parameterise the assembly process, and perform assembly-time calculations. | ||
| + | The constants can be integer, floating-point numeric, or text strings.\\ | ||
| + | Integer numeric constants can be defined with the data assignment directives, **EQU** or the equal sign **=**. The difference is that a numeric constant defined with the EQU directive can’t be modified later in the program, while a constant created with the equal sign can be redefined many times in the program. Numeric constants can be expressed as binary, octal, decimal or hexadecimal values. They can also be a result of an expression calculated during assembly time. It is possible to use a previously defined constant in such an expression. | ||
| + | <code asm> | ||
| + | int_const1 EQU 5 ; no suffix by default decimal value | ||
| + | int_const_dec = 7 ; finished with " | ||
| + | int_const_binary = 100100101b | ||
| + | int_const_octal = 372o ; finished with " | ||
| + | int_const_hex = 0FFA4h | ||
| + | int_const_expr = int_const_dec * 5 | ||
| + | </ | ||
| + | Floating-point numeric constants can be defined with the **EQU** directive only. The number can be expressed in decimal or scientific notation. | ||
| + | <code asm> | ||
| + | real_const1 EQU 3.1415 | ||
| + | real_const2 EQU 6.28e2 | ||
| + | </ | ||
| + | Text string constants can be defined with **EQU** or **TEXTEQU** directives. Text constants assigned with the **EQU** or **TEXTEQU** directive can be redefined later in the program. The **TEXEQU** is considered a text macro and is described in the section about macros. | ||
| + | <code asm> | ||
| + | text_const1 EQU 'Hello World!' | ||
| + | text_const2 EQU "Hello World!" | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Conditional assembly directives ===== | ||
| + | |||
| + | The condition assembly directives have the same functionality as in high-level language compilers. They control the assembly process by checking the defined conditions and enabling or disabling the process for fragments of the source code. | ||
| + | * **IF** expression, **IFE** expression - tests the value of the expression and performs (or do not) assemble according to the result (0-false), | ||
| + | * **IFDEF** symbol - tests whether a symbol is defined, | ||
| + | * **IFNDEF** symbol - tests whether a symbol is undefined, | ||
| + | * **IFB** < | ||
| + | * **IFNB** < | ||
| + | The conditional assembly statement, together with optional **ELSEIF** and **ELSE** statements, is shown in the following code. | ||
| + | <code asm> | ||
| + | IF expression1 | ||
| + | statements | ||
| + | [[ELSEIF expression2 | ||
| + | statements ]] | ||
| + | [[ELSE | ||
| + | statements ]] | ||
| + | ENDIF | ||
| </ | </ | ||
| ===== Statements ===== | ===== Statements ===== | ||