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
859
votes
17 answers

What's the purpose of the LEA instruction?

For me, it just seems like a funky MOV. What's its purpose and when should I use it?
user200557
  • 8,779
  • 3
  • 18
  • 8
101
votes
7 answers

How do I disassemble raw 16-bit x86 machine code?

I'd like to disassemble the MBR (first 512 bytes) of a bootable x86 disk that I have. I have copied the MBR to a file using dd if=/dev/my-device of=mbr bs=512 count=1 Any suggestions for a Linux utility that can disassemble the file mbr?
sigjuice
  • 28,661
  • 12
  • 68
  • 93
45
votes
3 answers

Cannot write to screen memory in C

I am very new to C, it's my second high-level programming language after Java. I have gotten most of the basics down, but for whatever reason I am unable to write a single character to screen memory. This program is compiled using Turbo C for DOS on…
Ampera
  • 440
  • 4
  • 13
42
votes
10 answers

How many ways to set a register to zero?

I'm curious how many ways are there to set a register to zero in x86 assembly. Using one instruction. Someone told me that he managed to find at least 10 ways to do it. The ones I can think of are: xor ax,ax mov ax, 0 and ax, 0
user173973
37
votes
2 answers

While, Do While, For loops in Assembly Language (emu8086)

I want to convert simple loops in high-level languages into assembly language (for emu8086) say, I have this code: for(int x = 0; x<=3; x++) { //Do something! } or int x=1; do{ //Do something! } while(x==1) or while(x==1){ //Do…
Glynn Bacanto
  • 439
  • 2
  • 6
  • 12
35
votes
9 answers

Difference between SHL and SAL in 80x86

I have learned how to work with 80x86 assembler, so in bit-wise shift operation, I faced a problem with SAL and SHL usage. I means the difference between lines of code as follow : MOV X, 0AAH SAL X, 4 MOV X, 0AAH SHL X, 4 When we should use SHL…
Hossein Mobasher
  • 4,382
  • 5
  • 46
  • 73
35
votes
6 answers

What is the purpose of CS and IP registers in Intel 8086 assembly?

So, as the question states, what is the purpose of CS and IP registers in intel's 8086 I found this explanation: Code segment (CS) is a 16-bit register containing address of 64 KB segment with processor instructions. The processor uses CS segment…
idjuradj
  • 1,355
  • 6
  • 19
  • 31
33
votes
6 answers

What are near, far and huge pointers?

Can anyone explain to me these pointers with a suitable example ... and when these pointers are used?
2easylogic
26
votes
4 answers

Set the leading zero bits in any size integer C++

I want to set the leading zero bits in any size integer to 1 in standard C++. eg. 0001 0011 0101 1111 -> 1111 0011 0101 1111 All the algorithms I've found to do this require a rather expensive leading zero count. However, it's odd. There are very…
dave_thenerd
  • 448
  • 3
  • 10
26
votes
2 answers

MUL function in assembly

I am trying to execute simple multiplication in Assembly. However, I do not see the registers change when the MUL function is called. mov bx, 5 mov cx, 10 mul cx
James Clark
  • 301
  • 1
  • 5
  • 7
26
votes
3 answers

8086- why can't we move an immediate data into segment register?

In 8086 assembly programming, we can only load a data into a segment register by, first loading it into a general purpose register and then we have to move it from this general register to the segment register. Why can't we load it directly? Is…
Rijo Joseph
  • 1,375
  • 3
  • 17
  • 33
23
votes
6 answers

What does OFFSET in 16 bit assembly code mean?

I am going through some example assembly code for 16-bit real mode. I've come across the lines: mov bx, cs mov ds, bx mov si, OFFSET value1 pop es mov di, OFFSET value2 what is this doing? What does having…
Without Me It Just Aweso
  • 4,593
  • 10
  • 35
  • 53
21
votes
3 answers

What does "int 21h" mean in Assembly?

I'm new to learning assembly language, and I'm wondering what the command int 21h means. For example: mov ah,01h int 21h Which should read a key from the user.
BOSS
  • 1,828
  • 11
  • 34
  • 60
20
votes
2 answers

Does modern PC video hardware support VGA text mode in HW, or does the BIOS emulate it (with System Management Mode)?

What really happens on modern PC hardware booted in 16-bit legacy BIOS MBR mode when you store a byte such as '1' (0x31) into the VGA text (mode 03) framebuffer at physical linear address B8000? How slow is a mov [es:di], eax store with the MTRR…
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
20
votes
3 answers

Is there a C compiler that targets the 8086?

I have an 8086 CPU emulator. It emulates only 8086 instructions. I am searching now for a C compiler to target this emulator with. Is there any C compiler out there that can do this? Also, having a usable libc and such is not important to me. The…
Earlz
  • 62,085
  • 98
  • 303
  • 499
1
2 3
99 100