Reverse byte order of EAX register

前端 未结 3 720
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 11:24

Example: 0xAABBCCDD will turn into 0xDDCCBBAA

My program crashes, due to Access Violation exception right in the first XOR operation.

3条回答
  •  失恋的感觉
    2020-12-18 12:18

    Why not simply:

     mov  eax, 0AABBCCDDh
     bswap eax
    

    I am not sure what you are trying to do in your program, but can say what the CPU actually tries to do (but can't and that is why crashes):

    This one:

    XOR BYTE PTR [eax], al 
    

    Tries to compute an xor operation of the value in the register AL (byte sized) and a value of the byte in memory at address 0AABBCCDDh (the content of EAX register). As long as on this address there is no any memory allocated by the OS, the program crashes with GPF.

    The proper byte swapping without using bswap is the following (Thanks to X.J):

        xchg  ah, al
        ror   eax, 16
        xchg  ah, al.
    

提交回复
热议问题