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
5
votes
2 answers

8086 random number generator (not just using the system time)?

I am using assembly 8086emu and I need a numbers generator for 8 numbers. I tried to use this piece of code by @johnfound: RANDGEN: ; generate a rand no using the system time RANDSTART: MOV AH, 00h ; interrupts to get system time …
Koren Minchev
  • 81
  • 1
  • 1
  • 7
5
votes
1 answer

Whats the fundamental difference between addressing of array[di] and [array + di] in assembly?

Given is the assembly program of Intel 8086 Processor which adds the numbers in array: .model small .stack 100h .data array dw 1,2,3,1,2 sum dw ?,", is the sum!$" .code main proc mov ax,@data mov ds,ax mov di,0 repeat: …
HQuser
  • 640
  • 10
  • 26
5
votes
1 answer

Where to place the stack and load the kernel

I'm new to operating system development and I'm curious about a problem I've run into while developing my own bootloader. My operating system is going to be written in assembly and will run in 16-bit real mode. I know what the stack is and I have…
DrCereal
  • 85
  • 8
5
votes
1 answer

INT 10h/ah=13h doesn't print strings when part of second stage bootloader

I used all the memory in the first sector, now I want to store a new variable string in the second sector (second stage) and print it. For instance: hello db 'Hello World' The new string should be in another sector (because there is no more memory…
JesMot
  • 53
  • 1
  • 4
5
votes
1 answer

Dot Product on 8086 and DSP microprocessor

My teacher tends to gave us a problem every year on the finals and seems that nobody gave him the expected result.Personally I don't have any clue how to solve it. Here is the problem Let's consider an array of constants A[a0 a1 a2 a3 a4 a5 a6 a7],…
Alberto12
  • 509
  • 2
  • 16
5
votes
1 answer

Displaying text video memory at 0xb8000 without using the C library

I have been writing kernel in C. I've been using the GCC cross-compiler, writing on a Windows system and targeting 16bit Real Mode. I don't have the C library available to write the kernel. I have started with some code which is suppose to print a…
Panther Coder
  • 1,058
  • 1
  • 16
  • 43
5
votes
1 answer

INT 16h/AH=0h doesn't wait for keystroke in my bootloader

I have written my first bootloader using GNU Assembler with AT&T syntax. It is suppose to print hello world to the screen then inform user that pressing any key will cause a reboot. Only after a key is pressed is a reboot suppose to be initiated. My…
Magda Aarsman
  • 191
  • 2
  • 15
5
votes
3 answers

Emulator displays "error byte 24h not found after 2000 bytes" using int21h/ah=09h

I have to do a simple calculator in assembly using EMU8086, but every time I try to launch it EMU8086 gives this error: INT 21h, AH=09h - address: 170B5 byte 24h not found after 2000 bytes. ; correct example of INT 21h/9h: mov dx, offset msg mov…
user4179055
5
votes
2 answers

Assembly Basics: Output register value

I just started learning assembly language and I am already stuck on the part to "display the decimal values stored in a register on the screen". Im using the emu8086, any help would be appreciated! :) .model small ;Specifies the memory model used…
user5675317
5
votes
2 answers

Cannot move 8 bit address to 16 bit register

I am trying to assign variable to register here is the code: ORG 100h var1 DB 10 ; var2 DB 20 ; MOV BX,var1 ; error : operands do not match: 16 bit register and 8 bit address RET END But if swap the 4th line…
Ven
  • 73
  • 1
  • 1
  • 4
5
votes
2 answers

TASM 1.4 - Displaying a particular colored string?

I'm using TASM 1.4 and I'm trying to make an output that will display different colored sentences, all in the same screen. I can make something that displays colored texts, but the words all have the same color. How do I make something that displays…
xTan
  • 77
  • 1
  • 11
5
votes
2 answers

stack segment and stack pointer in 8086

I'm a little bit confused with stack segment (ss) and stack pointer (sp) registers . when the stack is empty, is the sp value equal to the ss value ? I read that when we push a word (2bytes) to the stack the sp is decremented by 2, if the first…
5
votes
1 answer

Effective Address calculation time on 8086/8088

I've started to implement a 8086/8088 with the goal of being cycle-exact. I can understand the reasoning behind the number of clock cycles for most instructions, however I must say I'm quite puzzled by the Effective Address (EA) calculation…
Matthieu Wipliez
  • 1,901
  • 1
  • 16
  • 15
5
votes
2 answers

How does assembler compute segment and offset for symbol addresses?

I have learned about compilers and assembly language, so I'd like to write my own assembler as an exercise. But there I have some questions; How can I compute the address for segments such as @DATA or like OFFSET/ADDR VarA? Take an easy assembly…
5
votes
2 answers

effect of undefined opcodes on the (original) Intel 8086/88

Since the original 8086 and 8088 do not have a software exception for illegal instructions, how do they behave when fed such, for instance "FF FF" (not an opcode) ? Do they stall, do it reset itself, possibly emitting a special cycle indication on…
Ninho
  • 51
  • 2