我在汇编中写入一个无符号长整型函数。 这是一个UTF-8字符。程序集AT&T x86 - 如何比较长特定字节?
我想检查它是否是1个,2个,3个或4个字节的UTF-8字符。到目前为止,我有这样的:(我改变代码不被字节序的影响,我认为...)
movl 12(%ebp),%eax # Move long u to %eax
movl %eax,buff # Move long u to buff
andl $128,buff # &-mask 1 MSB (from LSByte)
cmpl $0,buff # Compare buff to 0
je wu8_1byte # If 0, 1 byte UTF8
movl 12(%ebp),%eax # Move long u to %eax
movl %eax,buff # Move long u to buff
andl $0xE000,buff # &-mask 3 MSB (from byte LSByte 2)
cmpl $0xC000,buff # Compare the 3 MSB to binary 110
je wu8_2byte # If =, 2 byte UTF8
movl 12(%ebp),%eax # Move long u to %eax
movl %eax,buff # Move long u to buff
andl $0xF00000,buff # &-mask 4 MSB (from byte MSByte 3)
cmpl $0xE00000,buff # Compare the 4 MSB to binary 1110
je wu8_3byte # If =, 3 byte UTF8
jmp wu8_4byte # If no, 4 byte UTF8
12(%EBP)是长我想工作。 Buff是一个4字节的变量。
它适用于1byte,但不适用于其他。
关于如何弄清楚它是什么类型的UTF-8字符的任何提示?
UTF-8编码:
0xxxxxxx # 1 byte
110xxxxx 10xxxxxx # 2 byte
1110xxxx 10xxxxxx 10xxxxxx # 3 byte
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx # 4 byte
当你说“这是一个UTF-8字符”时,它是否以大端形式编码?因为这对英特尔来说是不寻常的。 –
我很确定它是什么endianess。我使用gcc -m32编译它,并用C程序测试装配函数。 –
那么事实上,你将13位移动到前端字节的测试部分告诉我,你相信只要UTF-8字节序列以big endian顺序存储就可以了。你的系统的体系结构是小端的。这就是为什么我觉得很奇怪。 –