代码之家  ›  专栏  ›  技术社区  ›  Justin

x86新增(添加)

x86
  •  1
  • Justin  · 技术社区  · 8 年前

     1. create the following variables in the data section. Declare them as WORD (not BYTE or DWORD)  
        num1 (initialize to 0FACE hex)  
        num2 (initialize to 0FEED hex)  
        In the code section write code to do the following:
    2. You should populate the following registers with the following values in the following order:
        edx = 0D2C6FFFE hex  
        ebx = 0FFFFFFFFh  
        eax = 0FFFFFFFFh  
        bh = 249 decimal  
        bl = 11110111 binary  
        ecx = 0FFFFFFD3 hex  
    3. After you populate the above registers you should evaluate the following expression:
        eax = bl + bh + cx + num1 + num2 + edx
    

    eax = 3,356,452,476 (base 10)
    

    代码:

    mov     edx, 0d2c6fffeh ;edx = 0d2c6fffeh
    mov     ebx, 0ffffffffh ;ebx = 0ffffffffh
    mov     eax, 0ffffffffh ;eax = 0ffffffffh
    mov     bh,  249d       ;bh  = 249 (base 10) = 0f9h = 11111001b
    mov     bl,  11110111b  ;bl  = 11110111b = 0f7h = 247 (base 10)
    mov     ecx, 0ffffffd3h ;ecx = 0ffffffd3h
    
    movzx   esi, bl         ;copy bl to si and zero out upper part of esi
    mov     eax, esi        ;move eax to esi
    
    movzx   esi, bh         ;copy bh to si and zero out upper part of esi
    add     eax, esi        ;add eax to esi
    
    movzx   esi, cx         ;copy cx to si and zero out upper part of esi
    add     eax, esi        ;add eax to esi
    
    movzx   esi, num1       ;copy num1 to si and zero out upper part of esi
    add     eax, esi        ;add eax to esi
    
    movzx   esi, num2       ;copy num2 to si and zero out upper part of esi
    add     eax, esi        ;add eax to esi
    
    add     eax, edx        ;add eax to edx
    

    这是正确的吗?我不确定第一个是否应该使用mov或add(因为已经设置了eax),也不确定是否正确添加了变量。

    1 回复  |  直到 8 年前
        1
  •  3
  •   Peter Cordes    8 年前

    我不确定第一次使用mov还是add(因为eax已经设置好了),

    第3部分很清楚,EAX的新值不依赖于旧值,因此 movzx eax, bl 这是一个很好的开始。你的 movzx + mov 版本有效,但浪费指令。


    你的评论完全是多余的,不要添加指令本身中没有的任何新内容。老实说,这段代码实际上不需要注释,除了可能需要跟踪已经添加的内容,或者只需要对最终结果进行注释 add
    ; eax = bl + bh + ...

    通常,您的评论应该至少比asm本身高一个抽象级别;描述算法以及asm如何实现它,而不是从指令本身的角度在指令参考手册中查找什么。e、 g.如果 edx 持有一个你正在调用的值 x_distance ; eax += x_distance 在最后一条“add”指令上。

    movzx   esi, bh         ;copy bh to si and zero out upper part of esi
    

    bh sil sil公司 是的低字节 esi ,只能在x86-64模式下单独访问)。

    但你真的应该想想 作为零延伸 之前 零扩展;它只是用零扩展到32位的结果替换旧值。

    推荐文章