汇编程序打包数据

时间:2018-04-09 14:32:19

标签: assembly x86 inline-assembly

我需要编写用于在最小单元格内存中写入3个字母的单词的assebler代码 这张照片说明了我的需求:

enter image description here

我开始编写代码:

    mov eax, dword ptr str[0]
    bsr cl, eax
    inc cl
    shl eax, cl
    push eax
    //
    mov eax, dword ptr str[1]
    pop ebx
    or eax, ebx
    push eax // unshifted
    //
    mov eax, dword ptr str[2]
    bsr cl, eax
    inc cl
    pop ebx
    shl ebx, cl
    or eax, ebx
    mov result, ebx

但我得到-934608896(否定后为00110111101101010000000000000000)
而不是1304526(0100111110011111001110)

1 个答案:

答案 0 :(得分:5)

结果在EAX之后or eax, ebx。{ 为什么要将EBX放入结果?这是您检查的错误值吗?

这是一个在同一个寄存器中插入3位模式的代码:

movzx eax, byte ptr str[0]
movzx ebx, byte ptr str[1]
bsr   ecx, ebx
inc   ecx
shl   eax, cl
or    eax, ebx
movzx ebx, byte ptr str[2]
bsr   ecx, ebx
inc   ecx
shl   eax, cl
or    eax, ebx
mov   result, eax