flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > More-than-one-byte NOPs.

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
i dont got it.

Whats the difference betwen using NOPs and another thing to simulate a nop?

_________________
Sorry if bad english.
Post 11 Jun 2011, 14:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
Teehee wrote:
i dont got it.

Whats the difference betwen using NOPs and another thing to simulate a nop?
Longer NOPs (using multiple byte sequences for one instruction) require less decoder bandwidth and thus less CPU resources to execute than the equivalent multiple single byte NOPs.
Post 11 Jun 2011, 14:40
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
gotcha
Post 11 Jun 2011, 14:43
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
use this macro:
Code:
macro align value
 {
  virtual
    align value
    ..align = $ - $$
  end virtual
  virtual at 0
    lea eax,[dword 0]
    ..bitness = $
  end virtual
  if ..bitness = 6              ;use32
    times ..align/8 \
     db $3E,$8D,$B4,$26,$00,$00,$00,$00 ;lea esi,[ds:esi*1+$00000000]
    ..align = ..align mod 8
    if ..align = 7
     db $8D,$B4,$26,$00,$00,$00,$00     ;lea esi,[esi*1+$00000000]
    else if ..align = 6
     db $8D,$B6,$00,$00,$00,$00         ;lea esi,[esi+$00000000]
    else if ..align = 5
     db $3E,$8D,$74,$26,$00             ;lea esi,[ds:esi+$00]
    else if ..align = 4
     db $8D,$74,$26,$00                 ;lea esi,[esi+$00]
    else if ..align = 3
     db $8D,$76,$00                     ;lea esi,[esi+$00]
    else if ..align = 2
     db $89,$F6                         ;mov esi,esi
    else if ..align = 1
     db $90                             ;nop
    end if
  else if ..bitness = 7         ;use64
    times ..align/8 \
     db $48,$8D,$B4,$26,$00,$00,$00,$00 ;lea rsi,[rsi*1+$00000000]
    ..align = ..align mod 8
    if ..align = 7
     db $48,$8D,$B6,$00,$00,$00,$00     ;lea rsi,[rsi+$00000000]
    else if ..align = 6
     db $66,$48,$8D,$74,$26,$00         ;lea rsi,[rsi+$00]
    else if ..align = 5
     db $48,$8D,$74,$26,$00             ;lea rsi,[rsi+$00]
    else if ..align = 4
     db $48,$8D,$76,$00                 ;lea rsi,[rsi+$00]
    else if ..align = 3
     db $48,$89,$F6                     ;mov rsi,rsi
    else if ..align = 2
     db $40,$90                         ;rex,nop
    else if ..align = 1
     db $90                             ;nop
    end if
  else                          ;use16
    times ..align/8 \
     db $8D,$B4,$00,$00,$8D,$B4,$00,$00 ;lea si,[si+$0000];lea si,[si+$0000]
    ..align = ..align mod 8
    if ..align = 7
     db $8D,$B4,$00,$00,$8D,$74,$00     ;lea si,[si+$0000];lea si,[si+$00]
    else if ..align = 6
     db $8D,$B4,$00,$00,$89,$F6         ;lea si,[si+$0000];mov si,si
    else if ..align = 5
     db $3E,$8D,$B4,$00,$00             ;lea si,[ds:si+$0000]
    else if ..align = 4
     db $8D,$B4,$00,$00                 ;lea si,[si+$0000]
    else if ..align = 3
     db $8D,$74,$00                     ;lea si,[si+$00]
    else if ..align = 2
     db $89,$F6                         ;mov si,si
    else if ..align = 1
     db $90                             ;nop
    end if
  end if
 }

Test:
use16
nop
align 32
use32
nop
align 32
use64
nop
align 32
    
Post 24 Apr 2012, 22:11
View user's profile Send private message Reply with quote
TrDr.Charlie



Joined: 07 Dec 2010
Posts: 11
TrDr.Charlie
Code:

;*********************************************************************************************************
;*                                                                                                       *
;*      Results from my Intel Pentium(R) Dual-Core, T4400 @ 2.20 GHz                                     *
;*                                                                                                       *
;*      !!!! Tested in 64-bit mode                                                                       *
;*                                                                                                       *
;*********************************************************************************************************

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db  1 dup ( 90h )               ; 0.1584, Opcode(s) : 90

        db  2 dup ( 90h )               ; 0.7084, Opcode(s) : 90 90

        db  3 dup ( 90h )               ; 1.2584, Opcode(s) : 90 90 90

        db  4 dup ( 90h )               ; 1.8722, Opcode(s) : 90 90 90 90

        db  5 dup ( 90h )               ; 2.4827, Opcode(s) : 90 90 90 90 90

        db  6 dup ( 90h )               ; 3.0943, Opcode(s) : 90 90 90 90 90 90

        db  7 dup ( 90h )               ; 3.7048, Opcode(s) : 90 90 90 90 90 90 90

        db  8 dup ( 90h )               ; 4.3164, Opcode(s) : 90 90 90 90 90 90 90 90

        db  9 dup ( 90h )               ; 4.9269, Opcode(s) : 90 90 90 90 90 90 90 90 90

        db 10 dup ( 90h )               ; 5.5363, Opcode(s) : 90 90 90 90 90 90 90 90 90 90

        db 11 dup ( 90h )               ; 6.1468, Opcode(s) : 90 90 90 90 90 90 90 90 90 90 90

        db 12 dup ( 90h )               ; 6.7606, Opcode(s) : 90 90 90 90 90 90 90 90 90 90 90 90

        db 13 dup ( 90h )               ; 7.3711, Opcode(s) : 90 90 90 90 90 90 90 90 90 90 90 90 90

        db 14 dup ( 90h )               ; 7.9827, Opcode(s) : 90 90 90 90 90 90 90 90 90 90 90 90 90 90

        db 15 dup ( 90h )               ; 8.5932, Opcode(s) : 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db  1 dup ( 66h ), 90h          ; 0.1804, Opcode(s) : 66 90

        db  2 dup ( 66h ), 90h          ; 0.1804, Opcode(s) : 66 66 90

        db  3 dup ( 66h ), 90h          ; 0.1826, Opcode(s) : 66 66 66 90

        db  4 dup ( 66h ), 90h          ; 0.3652, Opcode(s) : 66 66 66 66 90

        db  5 dup ( 66h ), 90h          ; 0.3652, Opcode(s) : 66 66 66 66 66 90

        db  6 dup ( 66h ), 90h          ; 0.3894, Opcode(s) : 66 66 66 66 66 66 90

        db  7 dup ( 66h ), 90h          ; 0.5731, Opcode(s) : 66 66 66 66 66 66 66 90

        db  8 dup ( 66h ), 90h          ; 0.5731, Opcode(s) : 66 66 66 66 66 66 66 66 90

        db  9 dup ( 66h ), 90h          ; 0.7535, Opcode(s) : 66 66 66 66 66 66 66 66 66 90

        db 10 dup ( 66h ), 90h          ; 0.7535, Opcode(s) : 66 66 66 66 66 66 66 66 66 66 90

        db 11 dup ( 66h ), 90h          ; 0.9394, Opcode(s) : 66 66 66 66 66 66 66 66 66 66 66 90

        db 12 dup ( 66h ), 90h          ; 1.1231, Opcode(s) : 66 66 66 66 66 66 66 66 66 66 66 66 90

        db 13 dup ( 66h ), 90h          ; 1.1231, Opcode(s) : 66 66 66 66 66 66 66 66 66 66 66 66 66 90

        db 14 dup ( 66h ), 90h          ; 1.3057, Opcode(s) : 66 66 66 66 66 66 66 66 66 66 66 66 66 66 90

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db  7 dup ( 66h ), 90h          ; 1.3057, Opcode(s) : 66 66 66 66 66 66 66 90 66 66 66 66 66 66 90
        db  6 dup ( 66h ), 90h          ;

        db  4 dup ( 66h ), 90h          ; 1.3057, Opcode(s) : 66 66 66 66 90 66 66 66 66 90 66 66 66 66 90
        db  4 dup ( 66h ), 90h          ;
        db  4 dup ( 66h ), 90h          ;

        db  3 dup ( 66h ), 90h          ; 1.8722, Opcode(s) : 66 66 66 90 66 66 66 90 66 66 66 90 66 66 90
        db  3 dup ( 66h ), 90h          ;
        db  3 dup ( 66h ), 90h          ;
        db  2 dup ( 66h ), 90h          ;

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db $EB, 0                       ; 1.6247, Opcode(s) : EB 00
;       jmp     $ + 2

        db $E9, 0, 0, 0, 0              ; 1.6269, Opcode(s) : E9 00 00 00 00
;       jmp     $ + 5


;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db $87, $C0                     ; 4.0392, Opcode(s) : 87 C0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;       xchg    eax, eax

        db $89, $C0                     ; 1.1033, Opcode(s) : 89 C0
;       mov     eax, eax

        db $8B, $c0                     ; 1.1033, Opcode(s) : 8B C0
;       mov     eax, eax

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

        db $66, $8D, $04, $05, $00, $00, $00, $00
                                        ; 5.4758, Opcode(s) : 66 8D 04 05 00 00 00 00 !!!!!!!!!!!!!!!!!!!!
;       lea     ax, [1*rax + 00000000h] ( in 64-bit mode it is rax )

        db $8D, $04, $05, $00, $00, $00, $00
                                        ; 1.0769, Opcode(s) : 8D 04 05 00 00 00 00
;       lea     eax, [1*rax + 00000000h] ( in 64-bit mode it is rax )

        db $8D, $80, $00, $00, $00, $00
                                        ; 1.0769, Opcode(s) : 8D 80 00 00 00 00
;       lea     eax, [rax + 00000000h] ( in 64-bit mode it is rax )

;---------------------------------------------------------------------------------------------------------

        db $66, $8D, $54, $22, $00
                                        ; 5.4758, Opcode(s) : 66 8D 54 22 00 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;       lea     dx, [rdx + 0] ( in 64-bit mode it is rdx )

        db $66, $8D, $44, $20, $00
                                        ; 5.4758, Opcode(s) : 66 8D 44 20 00 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;       lea     ax, [rax + 0] ( in 64-bit mode it is rax )

;
;       !!!!!!!!!!!!!       in 64-bit mode
;

        db $67, $8D, $54, $22, $00
                                        ; 2.4057, Opcode(s) : 67 8D 54 22 00 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;       lea     edx, [edx + 0] ( in 64-bit mode it is edx )

        db $67, $8D, $44, $20, $00
                                        ; 2.4057, Opcode(s) : 67 8D 44 20 00 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;       lea     eax, [eax + 0] ( in 64-bit mode it is eax )

;---------------------------------------------------------------------------------------------------------

        db $8D, $44, $20, $00
                                        ; 1.0769, Opcode(s) : 8D 44 20 00
;       lea     eax, [rax + 0] ( in 64-bit mode it is rax )

        db $8D, $40, $00
                                        ; 1.0747, Opcode(s) : 8D 40 00
;       lea     eax, [rax + 0] ( in 64-bit mode it is rax )

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;       Opcode(s)                        Dynamic
;                                        Latency
;                                       (in Ticks)

;/////////////////////////////////////////////////////////////////////////////////////////////////////////

;
;       !!!!!!!!!!!!! used (e.g.) in my ntoskrnl.exe
;
        db  0Fh, 1Fh, 00                ; 1.2584, Opcode(s) : 0F 1F 00
;       nop     [rax]

        db  0Fh, 1Fh, 04h, 00           ; 1.2606, Opcode(s) : 0F 1F 04 00
;       nop     [rax + 1*rax]

        db  66h, 0Fh, 1Fh, 04h, 00      ; 1.2606, Opcode(s) : 66 0F 1F 04 00
;       nop     [rax + 1*rax]

;*********************************************************************************************************
;*                                                                                                       *
;*      For now all                                                                                      *
;*                                                                                                       *
;*********************************************************************************************************
    
Post 26 Apr 2012, 13:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2020, Tomasz Grysztar.

Powered by rwasa.