This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:multiasm:papc:chapter_6_12 [2026/02/27 02:10] – [Statements] jtokarz | en:multiasm:papc:chapter_6_12 [2026/06/22 17:08] (current) – pczekalski | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| An assembler, understood as software that translates assembler source code into machine code, can be implemented in various ways. While the processor' | An assembler, understood as software that translates assembler source code into machine code, can be implemented in various ways. While the processor' | ||
| ===== Alphabet ===== | ===== Alphabet ===== | ||
| - | An alphabet is a set of characters which can be used in writing programs. In MASM, they include | + | An alphabet is a set of characters which can be used in writing programs. In MASM, they include |
| * Letters: A…Z, a…z | * Letters: A…Z, a…z | ||
| * Digits: 0…9 | * Digits: 0…9 | ||
| Line 60: | Line 60: | ||
| ===== Operators ===== | ===== Operators ===== | ||
| - | Operators are used in expressions calculated during assembly. They enable | + | Operators are used in expressions calculated during assembly. They enable arithmetic and logical operations on numeric and address expressions. Some operators are associated with macros or other specific elements of assembler language. We'll present some of them. For details about all operators, please refer to the MASM documentation ((https:// |
| The operators which can be used in numeric expressions are | The operators which can be used in numeric expressions are | ||
| Line 92: | Line 92: | ||
| </ | </ | ||
| - | The **PTR** operator is similar to type casting in other programming languages. In some cases, it is required to specify the size of an operand. For example, if we have the indirect increment instruction. The assembler can't determine the size of the operand in memory pointed | + | The **PTR** operator is similar to type casting in other programming languages. In some cases, it is required to specify the size of an operand. For example, if we have the indirect increment instruction. The assembler can't determine the size of the operand in memory pointed |
| <code asm> | <code asm> | ||
| inc [RBX] ; Error! - argument size is not specified | inc [RBX] ; Error! - argument size is not specified | ||
| Line 112: | Line 112: | ||
| To start the code section, the **.CODE** directive is used. The code section contains all instructions in a program. To identify the beginning of the data section, the **.DATA** directive is used. The data section contains all the variables used in a program. | To start the code section, the **.CODE** directive is used. The code section contains all instructions in a program. To identify the beginning of the data section, the **.DATA** directive is used. The data section contains all the variables used in a program. | ||
| < | < | ||
| - | Up to 32-bit processors, the functional fragments of programs were referred to as segments. It was because they were assigned to segment registers in the processor. Currently, the segmentation mechanism is no longer operational, | + | Up to 32-bit processors, the functional fragments of programs were referred to as segments. It was because they were assigned to segment registers in the processor. Currently, the segmentation mechanism is no longer operational, |
| </ | </ | ||
| ===== Location counter ==== | ===== Location counter ==== | ||
| - | The location counter is an internal variable, maintained by the assembler, to assign addresses to program items. During assembly, it performs | + | The location counter is an internal variable, maintained by the assembler, to assign addresses to program items. During assembly, it serves |
| - | Any directive which starts a section defines a new location counter and sets it to 0. If the same section is continued | + | Any directive which starts a section defines a new location counter and sets it to 0. If the same section is continued |
| While the **SEGMENT** and **ENDS** directives are used, the **SEGMENT** directive, used for the specific section (segment) for the first time, creates the location counter for this section. The **ENDS** directive suspends byte counting in a given location counter until the next fragment of the section with the same name starts with another **SEGMENT** directive. | While the **SEGMENT** and **ENDS** directives are used, the **SEGMENT** directive, used for the specific section (segment) for the first time, creates the location counter for this section. The **ENDS** directive suspends byte counting in a given location counter until the next fragment of the section with the same name starts with another **SEGMENT** directive. | ||
| The current value of the location counter can be retrieved with the **$** sign. | The current value of the location counter can be retrieved with the **$** sign. | ||
| Line 129: | Line 129: | ||
| The **ALIGN** directive aligns the next variable or instruction on an address of a byte that is a multiple of the argument. | The **ALIGN** directive aligns the next variable or instruction on an address of a byte that is a multiple of the argument. | ||
| - | The argument of **ALIGN** must be a power of two. Empty spaces are filled with zeros for the data section or appropriately-sized **NOP** instructions | + | The argument of **ALIGN** must be a power of two. Empty spaces are filled with zeros in the data section or with appropriately sized **NOP** instructions |
| - | 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) | + | 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) is used for label definitions, but the **LABEL** directive |
| ===== Data definition directives ===== | ===== Data definition directives ===== | ||
| - | There is a set of directives for defining variables. They enable | + | There is a set of directives for defining variables. They enable |
| {{ref> | {{ref> | ||
| <table masmdatadefine> | <table masmdatadefine> | ||
| Line 170: | Line 170: | ||
| </ | </ | ||
| - | Previously | + | The previously |
| <code asm> | <code asm> | ||
| ; TYPE LENGHT | ; TYPE LENGHT | ||
| 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. Numeric constants can be expressed | + | 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 |
| <code asm> | <code asm> | ||
| int_const1 EQU 5 ; no suffix by default decimal value | int_const1 EQU 5 ; no suffix by default decimal value | ||
| Line 219: | Line 219: | ||
| ===== Conditional assembly directives ===== | ===== 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 | + | The condition assembly directives have the same functionality as in high-level language compilers. They control the assembly process by checking the specified |
| - | * **IF** expression, **IFE** expression - tests the value of the expression and performs (or do not) assemble according to the result (0-false), | + | * **IF** expression, **IFE** expression - tests the value of the expression and performs (or does not) assemble according to the result (0-false), |
| * **IFDEF** symbol - tests whether a symbol is defined, | * **IFDEF** symbol - tests whether a symbol is defined, | ||
| * **IFNDEF** symbol - tests whether a symbol is undefined, | * **IFNDEF** symbol - tests whether a symbol is undefined, | ||