Assembly Language Fundamentals: Interrupts, Memory, and MASM Directives
Classified in Computers
Written on in English with a size of 4.57 KB
Understanding System Interrupts and Functions
System interrupts are crucial for managing CPU operations and external device interactions. They can be broadly categorized into:
- CPU Interrupts: These are internal events, often referred to as software interrupts or exceptions, triggered by the CPU itself.
- Hardware Interrupts: Caused by external devices, signaling the CPU for attention (e.g., keyboard input, disk I/O).
Essential System Services and Functions
Beyond interrupts, various basic services are available for program interaction with the system:
ROM BIOS Functions
Functions available directly in the system's Read-Only Memory (ROM).
DOS BIOS Services
Basic functions provided by the Disk Operating System (DOS).
DOS Functions
High-level functions for handling file system operations and input/output (I/O).
Common DOS Interrupt Functions
Here are some of the most frequently used DOS interrupt functions:
- Function 01h: Reads a keyboard character and displays it at the current cursor position.
- Function 02h: Outputs a character from the processor (stored in the DL register) to the screen at the current cursor position.
- Function 09h: Displays a string of characters on the screen, starting from the current cursor position.
- Function 4Ch: Exits the current process with a return code. This allows the program to return control to the Operating System, sending a return code from the original program. This is one of several methods that can cause permanent program termination.
Memory Organization and Segments in Assembly
Program Memory Sections
Programs in memory are organized into multiple sections or segments, which are essential for managing program memory efficiently.
Key Memory Segments
The primary memory segments include:
- CS (Code Segment)
- This segment stores the machine language instructions of our program.
- DS (Data Segment)
- Global variables of the program are stored in this segment.
- SS (Stack Segment)
- This segment stores: calls to functions, parameters of called functions, and local variables. If recursion is too deep, there is a risk of filling the stack, which can lead to a runtime error called Stack Overflow.
- HS (Heap Segment)
- In this segment, objects that are created dynamically at runtime are stored.
MASM Directives for Assembly Programming
Introduction to MASM Directives
MASM (Microsoft Macro Assembler) provides a set of instructions known as directives. These directives are generally used to specify memory organization, perform conditional assembly, define macros, manage input/output, control files, generate listings and cross-references, define addresses, and declare program structure and data.
Important MASM Directives
Among the most important directives are those that define the instruction set and program segments:
Instruction Set Directives
These directives enable specific instruction sets for different microprocessors:
- .8086 (Default): Activates instructions for the 8086 and 8088, while inhibiting those for the 80186 and 80286.
- .8087 (Default): Activates instructions for the 8087, disabling those for the 80287.
- .186: Activates 80186 instructions.
- .286c: Enables 80286 instructions in unprotected mode.
- .286p: Enables 80286 instructions in both protected and unprotected modes.
- .287: Activates 80287 instructions.
Segment Directives
Regarding program structure, the SEGMENT
and ENDS
directives mark the beginning and end of a program segment.
A program segment is a collection of instructions and/or data whose addresses are all relative to the same segment register.
Alignment options, combination, and class information are provided to the linker (LINK) to adjust segments.
Alignment options include the following values:
byte
(uses any byte address)word
(uses any word address, 2 bytes)para
(uses paragraph address, 16 bytes, default)page
(uses page addresses, 256 bytes)