Chapter 3: Character Representation
### 3.1 Introduction
In assembly language programming, characters play a crucial role in representing textual information and interacting with users. This chapter explores the various character representation methods, including ASCII encoding, character sets, and how characters are manipulated in assembly language.
### 3.2 ASCII Encoding
#### 3.2.1 ASCII Basics
- **ASCII (American Standard Code for Information Interchange):**
- Standard character encoding using 7 or 8 bits to represent characters.
- **Character Set:**
- Includes printable characters, control characters, and special characters.
#### 3.2.2 ASCII Table
- **ASCII Table:**
- Maps each character to a unique numerical value (0 to 127 or 0 to 255).
### 3.3 Character Representation in Assembly
#### 3.3.1 `db` Directive
- **Declaration:**
- Use the `db` (define byte) directive to declare character variables.
- **Example:**
```assembly
char_var db 'A' ; Declares a character variable with ASCII 'A'
message db 'Hello' ; Declares a character array with the ASCII values of 'H', 'e', 'l', 'l', 'o'
```
### 3.4 String Operations
#### 3.4.1 String Declaration
- **Declaration:**
- Use the `db` directive to declare strings.
- **Example:**
```assembly
my_string db 'Assembly Language' ; Declares a string
```
#### 3.4.2 String Manipulation
- **String Length:**
- Determine the length of a string by counting characters.
- **String Concatenation:**
- Concatenate strings by copying characters from one string to another.
### 3.5 String Input and Output
#### 3.5.1 Outputting Strings
- **System Calls:**
- Use system calls to output strings to the console.
- **Example:**
```assembly
mov eax, 4 ; System call number for sys_write
mov ebx, 1 ; File descriptor (stdout)
mov ecx, my_string ; Pointer to the string
mov edx, 16 ; Length of the string
int 0x80 ; Invoke system call
```
#### 3.5.2 Inputting Strings
- **System Calls:**
- Use system calls to input strings from the user.
- **Example:**
```assembly
mov eax, 3 ; System call number for sys_read
mov ebx, 0 ; File descriptor (stdin)
mov ecx, buffer ; Buffer to store the input
mov edx, 255 ; Maximum length to read
int 0x80 ; Invoke system call
```
### 3.6 Conclusion
Character representation is a fundamental aspect of assembly language programming, especially when dealing with textual data. Understanding ASCII encoding, character sets, and string operations empowers you to work effectively with characters in your assembly programs.

Comments
Post a Comment