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
7
votes
1 answer

Enable the boot loader to load the second sector of a USB

I am learning the assembly language. I wrote a simple bootloader. After testing it out, it didn't work. Here is my code: [bits 16] [org 0x7c00] jmp start data: wolf_wel_msg db 'Welcome to Bootloader!!!',0x0D,0x0A,0 wolf_kernel_load db 'Loading…
7
votes
1 answer

the use of ASSUME directive in 8086 instruction set

In my textbook, its given that the ASSUME directive tells the assembler the names of the logical segments to use as the physical segments. And that it uses displacements from the start of the specified logical segment to code out instructions. …
Bala Kumar
  • 355
  • 2
  • 4
  • 12
7
votes
2 answers

nasm/ld "relocation truncated to fit: R_386_16"

Assembly: [BITS 16] global _start _start: mov ax, 0x07C0 mov ds, ax mov si, hw call print_string jmp $ print_string: mov ah, 0x0E .char: lodsb cmp al, 0 je .exit int 0x10 jmp .char .exit: ret times…
DutChen18
  • 1,133
  • 1
  • 7
  • 24
7
votes
2 answers

Difference between byte ptr and word ptr

I saw the following question on a test paper, Question VarM DWORD ABBF01598h Give the contents of registers al, bx, and dl after the execution of mov al, byte ptr VarM + 1 mov bx, word ptr VarM + 2 mov dl, byte ptr VarM + 3 Now I know word ptr…
user379888
6
votes
3 answers

How does x86 real-mode segments overlap help memory saving?

I'm teaching my 12 y.o. 8086 assembly language and yesterday we were talking memory, addressing and segmentation. I showed him how segments can be visualized as a sequence of overlapping 64Kb blocks starting on 16 byte boundaries, with the offset…
Andriy Volkov
  • 18,653
  • 9
  • 68
  • 83
6
votes
5 answers

Newline in 8086 assembly language: my text prints stair-stepped

I'm getting stair-step output like this My program works correctly, except that when I print a new line, and then print something in the current line, it shows on the next line but with some space before it. The program is this: (print a table of…
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
6
votes
1 answer

manipulating 32 bit numbers with 16 bit registers in 8086

Im trying to write a program which get two 6-digit decimal numbers and show the addition of them, but in 16 bit 8086 i defined numbers as double word and put LO in WORD 1 and HO in word 2. similar to below code but i dont have any idea to do…
6
votes
1 answer

Why can't my HELLO_WORLD string be loaded from section .data?

I am in the process of making a bootloader as a way for me to learn assembly. I have looked into using sections to organize and optimize my code, but one thing that doesn't work is when I call my printf function. When I have my HELLO_WORLD string…
6
votes
1 answer

What do the constraints "Rah" and "Ral" mean in extended inline assembly?

This question is inspired by a question asked by someone on another forum. In the following code what does the extended inline assembly constraint Rah and Ral mean. I haven't seen these before: #include void tty_write_char(uint8_t inchar,…
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
6
votes
1 answer

Assembly enter protected mode and jump back to real mode

I am developing a toy OS in assembly and I have a problem when switching from protected mode back to real mode. I have successfully switched to protected mode, called the kernel that writes text to [0xb8000] video memory, returned to the caller and…
DrCarnivore
  • 103
  • 6
6
votes
1 answer

Assembly does reading a plane in mode x needs a different output to the VGA ports from writing?

1I am writing in TASM 3.0 on DosBox 0.74 and I am trying to write in Mode x (Tweaked 13h, unchained mode 13), and I ran into a problem, how you can see in the image, every line is printed, but in every line, every group of four pixels only the color…
Erik Gelfat
  • 293
  • 1
  • 9
6
votes
1 answer

Mode X in Assembly x86-16, Why is plane 1 not printing and all the other planes are not in the correct order?

I am writing in TASM 3.0 on DosBox 0.74 and I am trying to write in Mode x (Tweaked 13h, unchained mode 13), but here you can see in the image, it's not quite right. It seems that plane 1 (second plane) is not printing at all, and all the others are…
Erik Gelfat
  • 293
  • 1
  • 9
6
votes
5 answers

Can a string literal in C be modified?

I recently had a question, I know that a pointer to a constant array initialized as it is in the code below, is in the .rodata region and that this region is only readable. However, I saw in pattern C11, that writing in this memory address behavior…
Yuri Albuquerque
  • 474
  • 3
  • 14
6
votes
1 answer

How to play sound on two different DOSBoxes simultaneously?

I have created the game "Angry Birds" in assembly 8086. My main problem now is that I want to play the song of the game while the main loop is running. I've already written the code for the music. I thought about using multi-threading but found out…
Boomer
  • 61
  • 3
6
votes
3 answers

CONCEPT OF MOV AX,CS and MOV DS,AX

Can someone please explain the functions of these three instructions? ORG 1000H MOV AX,CS MOV DS,AX I know what the code, data, and extra segments are in theory, but: How they are implemented in this program? Why is the entire segment…
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77