例子:0xAABBCCDD
会变成0xDDCCBBAA
反向字节顺序登记
我的程序崩溃,由于访问冲突异常就在第一XOR操作。
好像有一个更好的天真的解决方案,使用移动或旋转,但不管怎么说,这里是代码:
;; #########################################################################
.486
.model flat, stdcall
option casemap :none ; case sensitive
;; #########################################################################
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.code
;; The following program will flip the sequence of the bytes in the eax
;; example : 0xAABBCCDD will turn into 0xDDCCBBAA
start:
MOV eax, 0AABBCCDDh
XOR BYTE PTR [eax], al ;; Swap first byte and last byte
XOR al, BYTE PTR [eax]
XOR BYTE PTR [eax], al
XOR BYTE PTR [eax+1], ah ;; Swap 2nd byte of eax and 3rd byte
XOR ah, BYTE PTR [eax+1]
XOR BYTE PTR [eax+1], ah
end_prog:
;;Exit the program, eax is the exit code
push eax
call ExitProcess
END start
什么我错在这里做什么?有没有更好的解决方案?
因为我从来不知道有这样的操作码:)无论如何,你能看到为什么程序崩溃?或者如果有另一种解决方案而不使用bswap操作码? – idish
@idish - 答案是用某种解释编辑的。 – johnfound
我还是不明白什么是错的。我试图在0xAA和0xDD之间进行XOR操作。 (第一个字节和最后一个字节) – idish