Skip to content

Comment on Why do Windows functions all begin with a pointless MOV EDI, EDI instruction?

Comments

NOOP sequences in x86 are a fun subject. There's an interesting section in Intel's optimization guide somewhere (I'm too lazy to find it) that details "best practice" noop instructions of 1, 2, ... up to something like 9 bytes. These are used for alignment puposes too, where you need a few bytes of padding to make a loop-back target cache-line aligned or whatnot.

Check out the "smartalign" package in NASM: it contains 1-8 byte nop instructions for several different x86 variants: http://repo.or.cz/w/nasm.git/blob/a2c78555770990ed966c414da9...

You can use xxd and objdump to see which all of these translate into. For example, here's an 8-byte nop for x86-64:

  $ echo '0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00' | xxd -r > /tmp/bincode
  $ objdump -M intel -D -b binary -mi386 -Mx86-64 /tmp/bincode
  
  /tmp/bincode:     file format binary
  
  
  Disassembly of section .data:
  
  00000000 <.data>:
     0:   0f 1f 84 00 00 00 00    nop    DWORD PTR [rax+rax*1+0x0]
     7:   00
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.