flat assembler
Message board for the users of flat assembler.

Index > Main > B.S. WAP

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 12 Jun 2008, 22:28
Code:
define pope pop
use32

; [80386]

mov   eax,$01234567
mov   ecx,eax
mov   edx,eax
mov   esi,eax

; bswap esi ; Prohibited Sad

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 Very Happy

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 ? Wink

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 12 Jun 2008, 22:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20309
Location: In your JS exploiting you and your system
revolution 13 Jun 2008, 04:45
Code:
macro bswap reg {
    if reg eq eax
   xchg    ah,al
       ror     eax,16
      xchg    ah,al
    else if reg eq ebx
     xchg    bh,bl
       ror     ebx,16
      xchg    bh,bl
    else if reg eq ecx
     xchg    ch,cl
       ror     ecx,16
      xchg    ch,cl
    else if reg eq edx
     xchg    dh,dl
       ror     edx,16
      xchg    dh,dl
    else
   xchg    reg,eax
     xchg    ah,al
       ror     eax,16
      xchg    ah,al
       xchg    reg,eax
    end if
}    
Post 13 Jun 2008, 04:45
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 14 Jun 2008, 11:43
Oops Embarassed even easier than I had thought ... thanks Smile
Post 14 Jun 2008, 11:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.