我在彙編中寫入一個無符號長整型函數。 這是一個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順序存儲就可以了。你的系統的體系結構是小端的。這就是爲什麼我覺得很奇怪。 –