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/16 13:23] – [Constants] ktokarz | en:multiasm:papc:chapter_6_12 [2025/11/17 08:33] (current) – [Constants] ktokarz | ||
|---|---|---|---|
| Line 195: | Line 195: | ||
| 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. | 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.\\ | 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. | + | 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> | <code asm> | ||
| - | int_const1 EQU 5 | + | int_const1 EQU 5 ; no suffix by default decimal value |
| - | int_const2 | + | int_const_dec |
| - | </ | + | 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. | 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> | <code asm> | ||
| - | real_const1 | + | text_const1 |
| - | real_const2 | + | text_const2 |
| </ | </ | ||
| - | |||
| - | Text constant assigned with the EQU directive can be redefined later in the program. | ||
| - | |||
| - | Integer constants: | ||
| - | binary, 1b, 0101B, -10y, 111111Y | ||
| - | octal, 34o, -746O, 2167q, 0Q | ||
| - | decimal, 39, 12d, 1200D, -90t, 56T | ||
| - | hex, 0h, 14A6h, 0FE3H | ||
| - | .RADIX base directive: | ||
| - | (.RADIX 16) | ||
| - | Floating point constants: | ||
| - | decimal notation, 1.0, 3.1415, -0.5 | ||
| - | exponent notation, 1e5, 1.56e-2, -15.7e+12 | ||
| - | |||
| - | String is an array of characters. | ||
| - | ‘Hello world’ | ||
| - | ”123*x=??? | ||
| - | Equal notations: | ||
| - | mov BH,’A’ | ||
| - | mov BH,”A” | ||
| - | mov BH,41h | ||