Questions tagged [x86]

x86 is an architecture derived from the Intel 8086 CPU. The x86 family includes the 32-bit IA-32 and 64-bit x86-64 architectures, as well as legacy 16-bit architectures. Questions about the latter should be tagged [x86-16] and/or [emu8086]. Use the [x86-64] tag if your question is specific to 64-bit x86-64. For the x86 FPU, use the tag [x87]. For SSE1/2/3/4 / AVX* also use [sse], and any of [avx] / [avx2] / [avx512] that apply

The x86 family of CPUs contains 16-, 32-, and 64-bit processors from several manufacturers, with backward-compatible instruction sets, going back to the Intel 8086 introduced in 1978.

There is an tag for things specific to that architecture, but most of the info here applies to both. It makes more sense to collect everything here. Questions can be tagged with either or both. Questions specific to features only found in the x86-64 architecture, like RIP-relative addressing, clearly belong in x86-64. Questions like "how to speed up this code with vectors or any other tricks" are fine for x86, even if the intention is to compile for 64bit.

Related tag with tag-wikis:

  • wiki (some good SIMD guides), and (not much there)
  • wiki for guides specific to interfacing with a compiler that way.
  • wiki and wiki have more details about the differences between the two major x86 assembly syntaxes. And for Intel, how to spot which flavour of Intel syntax it is, like NASM vs. MASM/TASM.

Learning resources


Guides for performance tuning / optimisation:

Instruction set / asm syntax references:

OS-specific stuff: ABIs and system-call tables:






  • 16bit interrupt list: PC BIOS system calls (int 10h / int 16h / etc, AH=callnumber), DOS system calls (int 21h/AH=callnumber), and more.

memory ordering:

Specific behaviour of specific implementations

Q&As with good links, or directly useful answers:


FAQs / canonical answers:

If you have a problem involving one of these issues, don't ask a new question until you've read and understood the relevant Q&A.

(TODO: find better question links for these. Ideally questions that make a good duplicate target for new dups. Also, expand this.)


How to get started / Debugging tools + guides

Find a debugger that will let you single-step through your code, and display registers while that happens. This is essential. We get many questions on here that are something like "why doesn't this code work" that could have been solved with a debugger.

On Windows, Visual Studio has a built-in debugger. See Debugging ASM with Visual Studio - Register content will not display. And see Assembly programming - WinAsm vs Visual Studio 2017 for a walk-through of setting up a Visual Studio project for a MASM 32-bit or 64-bit Hello World console application.

On Linux: A widely-available debugger is gdb. See Debugging assembly for some basic stuff about using it on Linux. Also How can one see content of stack with GDB?

There are various GDB front-ends, including GDBgui. Also guides for vanilla GDB:

With layout asm and layout reg enabled, GDB will highlight which registers changes since the last stop. Use stepi to single-step by instructions. Use x to examine memory at a given address (useful when trying to figure out why your code crashed while trying to read or write at a given address). In a binary without symbols (or even sections), you can use starti instead of run to stop before the first instruction. (On older GDB without starti, you can use b *0 as a hack to get gdb to stop on an error.) Use help x or whatever for help on any command.

GNU tools have an Intel-syntax mode that's similar to MASM, which is nice to read but is rarely used for hand-written source (NASM/YASM is nice for that if you want to stick with open-source tools but avoid AT&T syntax):

Another key tool for debugging is tracing system calls. e.g. on a Unix system, strace ./a.out will show you the args and return values of all the system calls your code makes. It knows how to decode the args into symbolic values like O_RDWR, so it's much more convenient (and likely to catch brain-farts or wrong values for constants) than using a debugger to look at registers before/after an int or syscall instruction. Note that it doesn't work correctly on Linux int 0x80 32-bit ABI system calls in 64-bit processes: What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?.

To debug boot or kernel code, boot it in a bochs, qemu, or maybe even DOSBOX, or any other virtual machine / simulator / emulator. Use the debugging facilities of the VM to get way better information than the usual "it locks up" you will experience with buggy privileged code.

BOCHS is generally recommended for debugging real-mode bootloaders, especially ones that switch to protected mode; BOCHS's built-in debugger understands segmentation (unlike GDB), and can parse a GDT, IDT, and page tables to make sure you got the fields right.

14860 questions
69
votes
5 answers

How to write a disassembler?

I'm interested in writing an x86 dissembler as an educational project. The only real resource I have found is Spiral Space's, "How to write a disassembler". While this gives a nice high level description of the various components of a…
mmcdole
  • 86,293
  • 60
  • 181
  • 221
68
votes
3 answers

Is this "should not happen" crash an AMD Fusion CPU bug?

My company has started having a number of customers call in because our program is crashing with an access violation on their systems. The crash happens in SQLite 3.6.23.1, which we ship as part of our application. (We ship a custom build, in order…
Bradley Grainger
  • 24,251
  • 4
  • 79
  • 101
68
votes
1 answer

Do x86 instructions require their own encoding as well as all of their arguments to be present in memory at the same time?

I am trying to figure out whether it is possible to run a Linux VM whose RAM is only backed by a single physical page. To simulate this, I modified the nested page fault handler in KVM to remove the present bit from all nested page table (NPT)…
savvybug
  • 783
  • 2
  • 6
68
votes
3 answers

Why is there not a register that contains the higher bytes of EAX?

%AX = (%AH + %AL) So why not %EAX = (%SOME_REGISTER + %AX) for some register %SOME_REGISTER?
Sargun Dhillon
  • 1,688
  • 2
  • 18
  • 23
68
votes
8 answers

What do the brackets mean in x86 asm?

Given the following code: L1 db "word", 0 mov al, [L1] mov eax, L1 What do the brackets ([L1]) represent?
joek1975
  • 3,303
  • 5
  • 36
  • 44
66
votes
2 answers

Can I use Intel syntax of x86 assembly with GCC?

I want to write a small low level program. For some parts of it I will need to use assembly language, but the rest of the code will be written on C/C++. So, if I will use GCC to mix C/C++ with assembly code, do I need to use AT&T syntax or can I…
Hlib
  • 2,521
  • 5
  • 25
  • 33
66
votes
11 answers

Fast method to copy memory with translation - ARGB to BGR

Overview I have an image buffer that I need to convert to another format. The origin image buffer is four channels, 8 bits per channel, Alpha, Red, Green, and Blue. The destination buffer is three channels, 8 bits per channel, Blue, Green, and…
Adam Davis
  • 87,598
  • 55
  • 254
  • 328
65
votes
5 answers

To learn assembly - should I start with 32 bit or 64 bit?

I'm really wanting to learn assembly. I'm pretty good at c/c++, but want a better understanding of what's going on at a lower level. I realize that assembly related questions have been asked before, but I'm just looking for some direction that's…
Cam
  • 13,963
  • 16
  • 70
  • 121
64
votes
9 answers

x86 Assembly on a Mac

Does anyone know of any good tools (I'm looking for IDEs) to write assembly on the Mac. Xcode is a little cumbersome to me. Also, on the Intel Macs, can I use generic x86 asm? Or is there a modified instruction set? Any information about post…
matthewdunnam
  • 1,616
  • 2
  • 19
  • 34
64
votes
4 answers

How Do You Make An Assembler?

I'd like to make a simple x86 assembler. I'm wondering if there's any tutorials for making your own assembler. Or if there's a simple assembler that I could study. Also, I wonder what tools are used in looking at and handling the binary/hex of…
mudge
  • 6,757
  • 11
  • 43
  • 46
63
votes
3 answers

Why does leave do "mov esp,ebp" in x86 assembly?

It's said that the leave instruction is the same as : mov esp,ebp pop ebp But what is mov esp,ebp here for? It doesn't seem valid to me...
compile-fan
  • 15,145
  • 19
  • 53
  • 70
63
votes
2 answers

Why is Windows 32-bit called Windows x86 and not Windows x32?

The Windows operating system can be either 32 bit or 64 bit. The 64 bit version is called Windows x64 but the 32 bit version is called Windows x86. Why isn't it called Windows x32? What is the reason?
Bacteria
  • 7,810
  • 10
  • 47
  • 61
63
votes
2 answers

What is the purpose of the "PAUSE" instruction in x86?

I am trying to create a dumb version of a spin lock. Browsing the web, I came across a assembly instruction called "PAUSE" in x86 which is used to give hint to a processor that a spin-lock is currently running on this CPU. The intel manual and other…
prathmesh.kallurkar
  • 4,930
  • 8
  • 32
  • 48
63
votes
4 answers

What is better "int 0x80" or "syscall" in 32-bit code on Linux?

I study the Linux kernel and found out that for x86_64 architecture the interrupt int 0x80 doesn't work for calling system calls1. For the i386 architecture (32-bit x86 user-space), what is more preferable: syscall or int 0x80 and why? I use Linux…
Alex
  • 8,901
  • 11
  • 45
  • 79
62
votes
7 answers

Efficient integer compare function

The compare function is a function that takes two arguments a and b and returns an integer describing their order. If a is smaller than b, the result is some negative integer. If a is bigger than b, the result is some positive integer. Otherwise, a…
fredoverflow
  • 237,063
  • 85
  • 359
  • 638