define pope pop
use32
; [80386]
mov eax,$01234567
mov ecx,eax
mov edx,eax
mov esi,eax
; bswap esi ; Prohibited
nop
nop
; 22 Bytes, 7 instructions, 22+y cycles, uses stack,
; __NO__ register trashed (except stack), EAX
push eax ; 2
shl eax,8 ; 3
mov al,[esp+1] ; 4 ?
shl eax,16 ; 3
mov ah,[esp+2] ; 4 ?
mov al,[esp+3] ; 4 ?
add esp,4 ; 2 | POPE nothing
nop
nop
mov edi,eax
nop
nop
; 14 Bytes, 8 instructions, 24+4x cycles, uses stack,
; 1 register trashed, EAX
push eax ; 2
pope ax ; 4+x
pope bx ; 4+x
xchg al,ah ; 3
xchg bl,bh ; 3
push ax ; 2+x
push bx ; 2+x
pope eax ; 4
nop
nop
; 15 Bytes, 6 instructions, 16 cycles, 1 register trashed, ECX
xor ebx,ebx ; 2 | MOVNTQ EBX,0
xchg cl,ch ; 3
shrd ebx,ecx,16 ; 3 | ECX unmodified !!!
shr ecx,16 ; 3
xchg cl,ch ; 3
or ecx,ebx ; 2 | Add high 16 bits into result
nop
nop
; 14 Bytes, 5 instructions, 14+x cycles, 1 register trashed,
; result in different register: BSWAP EBX<-EDX
xchg dl,dh ; 3
shrd ebx,edx,16 ; 3 | EDX unmodified !!!
shr edx,16 ; 3
xchg dl,dh ; 3
mov bx,dx ; 2+x | Add low 16 bits into result
nop
nop
xor edx,edx
ud2
Any further / better ideas ?
