字符表示与内存组织访问详解
立即解锁
发布时间: 2025-08-22 01:32:31 阅读量: 2 订阅数: 8 


编写出色代码:理解机器
# 字符表示与内存组织访问详解
## 1. HyCode字符集特性
### 1.1 不区分大小写比较
在使用HyCode时,不区分大小写的字符比较变得更加简单。以下是HLA汇编代码示例:
```plaintext
// Check to see if CL is alphabetic. No need to check DL as the comparison
// will always fail if DL is non-alphabetic.
cmp( cl, 76 ); // If CL < 76 ('a') then it's not alphabetic
jb TestEqual; // and there is no way the two chars are equal
// (even ignoring case).
or( 1, cl ); // CL is alpha, force it to uppercase.
or( 1, dl ); // DL may or may not be alpha. Force to
// uppercase if it is.
TestEqual:
cmp( cl, dl ); // Compare the uppercase versions of the chars.
jne NotEqual; // Bail out if they're not equal.
TheyreEqual:
// do code that handles c==d using a case-insensitive comparison.
NotEqual:
```
可以看到,HyCode序列在进行两个字符的不区分大小写比较时,使用的指令减少了一半。
### 1.2 其他字符分组
由于字母字符和数字字符分别位于字符编码范围的两端,检查一个字符是否为字母数字字符只需进行两次比较,这比使用ASCII时所需的四次比较要好。以下是用于检查字符是否为字母数字字符的Pascal/Delphi/Kylix代码:
```plaintext
if( ch < chr(10) or ch >= chr(76)) then ...
```
许多程序需要高效处理表示程序标识符的字符串。大多数语言允许标识符中使用字母数字字符,通过两次比较就可以检查一个字符是否为字母数字字符。许多语言还允许标识符中使用下划线,一些语言如MASM和TASM允许使用`@`和`$`等字符。通过为下划线字符赋值75,为`$`和`@`字符分别赋值73和74,仍然可以仅通过两次比较来测试一个字符是否为标识符字符。
HyCode字符集将其他几类字符分组到连续的字符编码范围中,例如光标控制键、空白字符、括号字符、算术运算符、标点字符等。以下是完整的HyCode字符集表格:
| Binary | Hex | Decimal | Character | Binary | Hex | Decimal | Character |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 0000_0000 | 00 | 0 | 0 | 0001_1110 | 1E | 30 | End |
| 0000_0001 | 01 | 1 | 1 | 0001_1111 | 1F | 31 | Home |
| 0000_0010 | 02 | 2 | 2 | 0010_0000 | 20 | 32 | PgDn |
| 0000_0011 | 03 | 3 | 3 | 0010_0001 | 21 | 33 | PgUp |
| 0000_0100 | 04 | 4 | 4 | 0010_0010 | 22 | 34 | left |
| 0000_0101 | 05 | 5 | 5 | 0010_0011 | 23 | 35 | right |
| 0000_0110 | 06 | 6 | 6 | 0010_0100 | 24 | 36 | up |
| 0000_0111 | 07 | 7 | 7 | 0010_0101 | 25 | 37 | down/linefeed |
| 0000_1000 | 08 | 8 | 8 | 0010_0110 | 26 | 38 | nonbreaking space |
| 0000_1001 | 09 | 9 | 9 | 0010_0111 | 27 | 39 | paragraph |
| 0000_1010 | 0A | 10 | keypad | 0010_1000 | 28 | 40 | carriage return |
| 0000_1011 | 0B | 11 | cursor | 0010_1001 | 29 | 41 | newline/enter |
| 0000_1100 | 0C | 12 | function | 0010_1010 | 2A | 42 | tab |
| 0000_1101 | 0D | 13 | alt | 0010_1011 | 2B | 43 | space |
| 0000_1110 | 0E | 14 | control | 0010_1100 | 2C | 44 | ( |
| 0000_1111 | 0F | 15 | command | 0010_1101 | 2D | 45 | ) |
| 0001_0000 | 10 | 16 | len | 0010_1110 | 2E | 46 | [ |
| 0001_0001 | 11 | 17 | len128 | 0010_1111 | 2F | 47 | ] |
| 0001_0010 | 12 | 18 | bin128 | 0011_0000 | 30 | 48 | { |
| 0001_0011 | 13 | 19 | EOS | 0011_0001 | 31 | 49 | } |
| 0001_0100 | 14 | 20 | EOF | 0011_0010 | 32 | 50 | < |
| 0001_0101 | 15 | 21 | sentinel | 0011_0011 | 33 | 51 | > |
| 0001_0110 | 16 | 22 | break/interrupt | 0011_0100 | 34 | 52 | = |
| 0001_0111 | 17 | 23 | escape/cancel | 0011_0101 | 35 | 53 | ^ |
| 0001_1000 | 18 | 24 | pause | 0011_0110 | 36 | 54 | \| |
| 0001_1001 | 19 | 25 | bell | 0011_0111 | 37 | 55 | & |
| 0001_1010 | 1A | 26 | back tab | 0011_1000 | 38 | 56 | - |
| 0001_1011 | 1B | 27 | backspace | 0011_1001 | 39 | 57 | + |
| 0001_1100 | 1C | 28 | delete | 0001_1101 | 1D | 29 | Insert |
| 0011_1010 |
0
0
复制全文
相关推荐









