Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en:multiasm:papc:chapter_6_12 [2026/02/27 02:10] – [Statements] jtokarzen: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's instructions remain constant, other language elements may be implementation-specific. In this chapter, we present the most important language elements specific to the MASM assembly implementation. For a detailed description of MASM assembler language implementation, please refer to the Microsoft© website((https://learn.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=msvc-170)). An assembler, understood as software that translates assembler source code into machine code, can be implemented in various ways. While the processor's instructions remain constant, other language elements may be implementation-specific. In this chapter, we present the most important language elements specific to the MASM assembly implementation. For a detailed description of MASM assembler language implementation, please refer to the Microsoft© website((https://learn.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=msvc-170)).
 ===== Alphabet ===== ===== Alphabet =====
-An alphabet is a set of characters which can be used in writing programs. In MASM, they include small and capital letters, digits, hidden characters and special characters.+An alphabet is a set of characters which can be used in writing programs. In MASM, they include lowercase and uppercase letters, digits, hidden charactersand special characters.
   * 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 performing arithmetic and logic calculations with numeric expressions 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://learn.microsoft.com/en-us/cpp/assembler/masm/operators-reference?view=msvc-170)).+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://learn.microsoft.com/en-us/cpp/assembler/masm/operators-reference?view=msvc-170)).
  
 The operators which can be used in numeric expressions are  The operators which can be used in numeric expressions are 
Line 92: Line 92:
 </note> </note>
  
-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 with the RBX register, which is why we have to specify the operand size with the PTR operator.+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 to by the RBX register, which is why we have to specify the operand size with the PTR operator.
 <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.
 <note> <note>
-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, so the code and data fragments of programs are named sections. However, in many literature sources and internet websites, the name segment can still be frequently found.+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, so program code and data fragments are named sections. However, in many sources in the literature and on websites, the name segment is still frequently found.
 </note> </note>
  
 ===== 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 similar role as the instruction pointer during program execution. The location counter contains the address of the currently processed variable in data section and the instruction in code section. +The location counter is an internal variable, maintained by the assembler, to assign addresses to program items. During assembly, it serves a role similar to that of the instruction pointer during program execution. The location counter contains the address of the currently processed variable in the data section and the address of the instruction in the code section. 
-Any directive which starts a section defines a new location counter and sets it to 0. If the same section is continued in another place in a program, the location counter increments continuously throughout the whole section. Assembling subsequent bytes increases the content of the location counter by 1.+Any directive which starts a section defines a new location counter and sets it to 0. If the same section is continued elsewhere in a program, the location counter increments continuously throughout the entire section. Assembling subsequent bytes increments the location counter by 1.
 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 for the code section. Note that **ALIGN 2** is equal to **EVEN**.+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 in the code section. Note that **ALIGN 2** is equal to **EVEN**.
  
-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. Usuallyin a program, the **:** (colon) is used for label definitions, but the **LABEL** directive allows specifying the type of element the label points to.
  
 ===== Data definition directives ===== ===== 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 assigning a name to a variable and specifying its type. They are summarised in a table
 {{ref>masmdatadefine}}. {{ref>masmdatadefine}}.
 <table masmdatadefine> <table masmdatadefine>
Line 170: Line 170:
 </code> </code>
  
-Previously mentioned **DUP** operator and type operators can be explained with some exemplary data definitions.+The previously mentioned **DUP** and type operators can be explained using some example data definitions.
 <code asm> <code asm>
            ; TYPE    LENGHT   SIZE            ; TYPE    LENGHT   SIZE
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 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.+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 in binary, octal, decimalor hexadecimal. They can also result from 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                ; 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 conditions and enabling or disabling the process for fragments of the source code. +The condition assembly directives have the same functionality as in high-level language compilers. They control the assembly process by checking the specified conditions and deactivating or activating it for source code fragments
-  * **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,
en/multiasm/papc/chapter_6_12.txt · Last modified: by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0