Questions tagged [x86-16]

For programming and/or microarchitecture questions about the 16-bit x86 Intel CPUs, including the 8088, 8086, and later chips running in 16-bit mode.

x86-16 refers to the 16-bit family of instruction set architectures (ISAs) based on the Intel 8086 CPU. This processor was designed by Intel in the mid-1970s, and gave rise to the x86 architecture.

See the tag wiki for links to x86 ISA and assembly-language programming resources (mostly aimed at modern 32-bit and 64-bit implementations).

The 8086 uses the same instruction set as later processors, but it is limited to 16-bit mode and lacks support for instructions added with 186, 286, 386 (or later). This means that extremely useful instructions like movzx are unavailable, so many operations require moving data into ax for use with instructions that have it as an implicit operand. The 16-bit implementation of x86 is also limited with respect to which registers can be used in addressing modes. This addressing limitation persists in modern CPUs running in 16-bit mode, because the machine-code format is the same.

The 8088 is a derivative of the 8086. The 8088 is identical in functionality to the 8086 and is fully 16-bit internally, but it has an 8-bit external data bus (instead of the 8086's 16-bit external data bus). In terms of programming, there are no salient differences between the 8088 and 8086, so these are combined under a single tag. Feel free to mention which specific chip you're targeting in the body and/or title of the question, though.

This tag is also appropriate for questions about non-Intel CPUs that use the same instruction set as the 8086, including the NEC v20 and v30, AMD 8086 clones, etc. There are also some modern microcontrollers that use simple 8086 cores.

Note that, while it will run on modern x86 CPUs, code that uses only the 16-bit instructions (as would be supported on an 8086) is not usually considered good or efficient code.

However, there remains much interest in writing 16-bit code for emulators (such as DOSBox and ) and real vintage hardware, both from beginners and enthusiasts. retrocomputing.SE has an 8086 tag, but unless you're asking about actual ancient hardware, Stack Overflow is the right place for questions about 16-bit bootloaders, kernels, and DOS executables. Retrocomputing is mostly about even older systems, like 8-bit micros.



Debuggers

Single-stepping in a debugger and looking at registers is essential. Trying to write a program without one is like trying to build a robot blindfolded. It's very much worth the time to learn to use one. For 32/64-bit mode under a modern OS, see the debugging section at the bottom of the x86 tag wiki.

Under DOS:

  • @ecm's lDebug, based on debug.com from FreeDOS.
  • Turbo Debugger is widely recommended, and maybe can be found for free
  • debug.exe/debug.com in MS-DOS or FreeDOS is an option, although classic MS-DOS DEBUG is pretty terrible to actually program in, not having labels, only numeric addresses for jump targets and so on!

Full system (for bootloaders, or maybe DOS programs)

  • Bochs is usually the gold standard, with a built-in debugger that's aware of segmentation. Manual. Note that it's an optional config feature; some builds might not come with it enabled. It's great for debugging the switch to 32-bit protected mode, and 64-bit mode. It can parse and dump your GDT and page tables, to help you spot mistakes in what you put there, and it knows what mode the CPU is in so it will disassemble in the right mode to match execution, helping you catch mistakes where code was assembled for the wrong bitness.
  • QEMU: can act as a remote for GDB. GDB doesn't know about segmentation so this isn't ideal for real mode or during the switch to protected mode.
  • DOSBox: There's a DOSBox-X fork with a built-in debugger, and the mainline DOSBox apparently also has a debugger built-in. (Curses-based text UI)

Related Tags:

  • (for the x86 in general, including 32-bit and 64-bit. Lots of good stuff in the tag wiki, including some 16-bit links)
  • (for stuff specifically about the 64-bit extensions to the x86 ISA)
  • (for the legacy numeric coprocessor—aka floating point unit, as opposed to the SSE/SSE2 FPU)
  • (for programs written in assembly language of any kind, including x86, MIPS, ARM, and toy architectures like LC-3)
  • (for programs targeting DOS and/or questions about DOS APIs)
  • (for questions specifically about the EMU8086 emulator package, often used by students)
2894 questions
20
votes
4 answers

Most Efficient way to set Register to 1 or (-1) on original 8086

I am taking an assembly course now, and the guy who checks our home assignments is a very pedantic old-school optimization freak. For example he deducts 10% if he sees: mov ax, 0 instead of: xor ax,ax even if it's only used once. I am not a…
Bob
  • 2,586
  • 7
  • 20
  • 33
18
votes
10 answers

Looking for 16-bit x86 compiler

I am working on an embedded systems project and have run into an issue of the compiler being programatically embedded in the Paradigm C++ IDE. I would like to be able to automate building. The processor is the AMD186ES. I am not working with the OS…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
17
votes
1 answer

Boot loader doesn't jump to kernel code

I'm writing small operation system - for practice. I started with bootloader. I want to create small command system that runs in 16 bit real mode (for now). I've created bootloader that resets drive, then loads sector after bootloader. The problem…
vakus
  • 732
  • 1
  • 10
  • 24
15
votes
2 answers

What do ds:si and es:di mean in assembly?

The movsb (move string, bytes) instruction fetches the byte at address ds:si, stores it at address es:di, and then increments or decrements the si and di registers by one. I know esi,si and edi,di registers, but not ds:si and es:di , what do…
new_perl
  • 7,345
  • 11
  • 42
  • 72
14
votes
1 answer

What is a paragraph (when referring to memory)

I feel silly for asking something that seems like it should be so easy to look up, but as you might guess, searching for paragraph gets a lot results that have nothing to do with what I want to know. I've been learning assembly these past few days…
cost
  • 4,420
  • 8
  • 48
  • 80
14
votes
2 answers

What is meaning of .model small in 8086 programs?

I am a beginner in 8086 assembly language. I can understand the logic used in the program and write small programs myself. But I just want to know what this does: .model small .stack 300h What is explanation for .model small? I am using masm.
Sakil Mallick
  • 177
  • 1
  • 1
  • 9
14
votes
6 answers

What are the segment and offset in real mode memory addressing?

I am reading about memory addressing. I read about segment offset and then about descriptor offset. I know how to calculate the exact addresses in real mode. All this is OK, but I am unable to understand what exactly offset is? Everywhere I…
narayanpatra
  • 5,627
  • 13
  • 51
  • 60
14
votes
4 answers

How to tell GCC to generate 16-bit code for real mode

I am writing real mode function, which should be normal function with stackframes and so, but it should use %sp instead of %esp. Is there some way to do it?
user2443423
  • 175
  • 1
  • 1
  • 9
12
votes
1 answer

Why does DOS set the SP register to 0xFFFE after loading a .COM file?

On the wikpedia page about .COM files https://en.wikipedia.org/wiki/COM_file it reads: .COM files in DOS set all x86 segment registers to the same value and the SP (stack pointer) register to 0xFFFE, thus the stack begins at the very top of the…
nadder
  • 193
  • 6
12
votes
4 answers

ADC instruction in ASM 8086

When I use ADC for exmaple: AL = 01 and BL = 02, and CF = 1 when I make this: ADC AL,BL Will AL be 3 or 4? (with the CF addition or without?)
Tal
  • 303
  • 1
  • 6
  • 11
12
votes
7 answers

How can I create a sleep function in 16bit MASM Assembly x86?

I am trying to create a sleep/delay procedure in 16bit MASM Assembly x86 that will, say, print a character on the screen every 500ms. From the research I have done, it seems that there are three methods to achieve this - I would like to use the one…
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
11
votes
9 answers

Real mode BIOS routine and Protected Mode

I am doing some OS experiment. Until now, all my code utilized the real mode BIOS interrupt to manipulate hard disk and floppy. But once my code enabled the Protect Mode of the CPU, all the real mode BIOS interrupt service routine won't be…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
11
votes
2 answers

What is the difference between RCR and ROR?

I understand the from the terms that RCR would rotate the bit from the right to left, taking the bit from the carry while ROR will rotate the bit from right to left, taking the bit from the right but is that the only difference between them? If this…
Foo
  • 309
  • 2
  • 5
  • 10
10
votes
5 answers

8086/88 emulator for ubuntu

I need to emulate assembly for 8086 program in Ubuntu. I searched repository and I found 8085 emulator which is not similar to 8086. Is there any 8086/88 assembly emulator for ubuntu?
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
10
votes
2 answers

Generating a random number within range of 0-9 in x86 8086 Assembly

First of all, I am very new to 8086 Assembly and it has been pretty difficult for me the grab the knowledge. Nevertheless, I'll do my best. I have been trying to write a code to generate a random number within range of 0-9. After looking into…
Raf
  • 115
  • 1
  • 2
  • 9