Ass-Lec3
Chapter Overview
Assembly Language Chapter 3: Slides prepared by Kip R. Irvine, modified by Dr. Karim Emara and Dr. Salsabil Amin.
Copyright Information: Copyright by Pearson Education, 2014. Modifications are permitted for personal and educational usage, emphasizing the importance of educational resources in the study of assembly programming.
Agenda
Defining Data Variables: Understanding various types and storage needs in assembly language, including their implications on performance.
Symbolic Constants: Use and importance of constants in programming for clarity and maintenance.
Data Transfer Instructions: Instruction sets for transferring data effectively between computational resources.
Addressing Modes: The methods used to access data stored in memory, with examples of each type.
ADD/SUB Instructions: Fundamental operations for arithmetic processes in assembly programming.
Key Points to Remember:
Size Considerations: Understanding memory size, including Byte (1 byte), Word (2 bytes), and DWORD (4 bytes).
Little Endian Order: The significance of byte order in memory representation, affecting data interpretation.
Examples of specific byte allocations to illustrate best practices in data management.
Char and String Variables
Variable Definitions:
StrVar:
BYTE 'abcd', 0- Represents a string variable terminated by a null character.CharArrB:
BYTE 'a', 'b', 'c', 'd'- Array of characters stored as bytes.CharWord:
Word 'z' ; 0z- An example of storing a single character in a word-sized storage.CharArrW:
Word 'w', 'x', 'y', 'z'- Array of characters stored in words, highlighting the advantages of using word-sized data types.StrWord:
Word 'ab' ; caution required- Noting potential risks of incorrect string length allocations.
Error Examples:
StrWord2:
Word 'abcd' ; error- An example indicating improper storage leading to buffer overflow.Strdword:
DWord 'abcd' ; caution- Emphasizes restrictions regarding storage sizes.StrDWord2:
DWord 'ab'- Possible data loss or mishandling noted here.StrDWord3:
Dword 'abcde' ; error- Indicates potential data integrity issues without proper size considerations.
Memory Content Examples
Word Examples
Variables:
WordVal0 WORD ?- Declaration of a word-sized variable without initialization.WordVal1 WORD 0FF30h- Initialization of a variable with a hexadecimal constant.WordVal2 WORD 300, 3 Dup(5), 12- Demonstrates advanced initialization techniques using duplication.
Memory Content:
Memory content visualization starting at
0x4025, emphasizing that representation in Hex format may vary based on usage ofDWORDdirectives across different systems.
Memory Address Breakdown:
Memory Addresses:
0x4025 ?- An uninitialized word variable.0x4027 30h- Initialized value.0x4028 FFh- Shows a critical concept of value representation in memory.0x4029 2Ch- Detailed values as exemplifications of memory allocation.
Symbolic Constants
Definition and Usage:
Symbolic Constants: Essential in programming as they attach identifiers to numeric expressions or constant texts while efficiently managing storage.
Declaring Symbolic Constants:
Equal sign (=) for integer expressions, improving code readability.
EQU for both integers and text constants, allowing for better resource management and ease of updates.
Example of Symbolic Constants:
PI EQU 3.1416- Practical implementation illustrating the concept's utility in mathematical operations.Additional examples showcasing how symbolic constants make modifications simpler across large codebases.
Equal-Sign Directive
Definition:
Syntax:
name = expressionRole of the
nameas a symbolic constant which can be redefined later enhances code adaptability.
Example:
COUNT = 500- Clarifies use in loops by providing a semantic meaning.
Size Calculation of Arrays
Byte Array
Current Location Counter ($): Utilized to help determine the location size dynamically during coding.
Size Calculation Explained:
Byte Array Example:
list BYTE 10h, 20h, 30h, 40hListSize = ($ - list)- This practical application showcases total byte counting.
Word Array
Explains analogous calculations for different types of arrays, specifically dividing by respective size for accurate increments in storage.
Data Transfer Instructions
MOV Instruction: Primary operation for data transfer, highlighting its pivotal role in effective assembly language programming.
Operand Types: Various types emphasized, including immediate values, registers, and memory locations.
Restrictions on MOV Instruction:
Uniform Size Requirement: Both operands must match in size.
Memory-to-Memory Operations Disallowed: Explains a critical restriction in data handling.
Usage of Registers: Specific registers such as EIP and IP have limitations as destinations.
Restrictions: Immediate values cannot be moved to segment registers which poses important rules to remember.
Addressing Modes
Types of Addressing:
Immediate value addressing, where constant values are directly utilized.
Register addressing, a technique where data stored in registers is accessed.
Direct memory addressing for fetching data from specific memory locations.
Direct offset addressing, which allows constants to enhance label references for effective data management.
Example: Addressing Modes
Register Addressing Example:
MOV AX, DX- Illustrating data transfer.
Direct Memory Addressing Example:
MOV AX, Var1- Another clear example for reference.
Key Considerations:
Emphasizes effective address calculations in relation to byte offsets within arrays (e.g.,
mov al, arrayB + 1).
Addition and Subtraction Instructions
Overview:
Operations formatted as
ADD/SUB destination, sourceshowcasing how assembly handles arithmetic.Memory-to-Memory Operations: Explicitly outlined as not permitted.
Practical Example of ADD Instruction
Providing a detailed walkthrough for adding three unsigned bytes using proper register utilization, reinforcing rules for size to prevent errors.
Final Thought: Resources
Textbook Chapters Referenced:
Chapter 3 covers Sections 3.4 - 3.5 and Chapter 4 includes 4.1 – 4.2, essential for further understanding of assembly programming concepts.
Exercises:
Chapter 3 Exercises includes 3.9.1 & 3.9.2, providing a practical application of learned topics.
Acknowledgment
Thank you for your attention in promoting understanding and proficiency in assembly language programming.