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

Define byte appearing in debug after a manually encoded far call

I couldn't get MASM to accept a far call instruction written as call 0f000h:1260h, probably because of the issues brought up in this question. Instead of messing around with cryptic MASM directives, I decided to manually encode it into my program…
bad
  • 939
  • 6
  • 18
8
votes
1 answer

How can linux boot code be written in C?

I'm a newbie to learning OS development. From the book I read, it said that boot loader will copy first MBR into 0x7c00, and starts from there in real mode. And, example starts with 16 bit assembly code. But, when I looked at today's linux kernel,…
8
votes
1 answer

SAL/SAR vs SHR/SAR in assembly 8086

I am learning assembly language (specific to x86). I have understood that the SAL and SHL works in similar way (clearing the lsb and carrying the msb to CF) from here Difference between SHL and SAL in 80x86. Considering that SHR and SAR doesn't…
Abrar
  • 6,874
  • 9
  • 28
  • 41
8
votes
2 answers

understanding nasm assembly for outputting characters in teletype mode

I am reading this wonderful skript on operating system programming http://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf On Page 12 there is a simple bootloader. If I understand correclty, the code shown is what you must write in…
user3813234
  • 1,580
  • 1
  • 29
  • 44
8
votes
1 answer

What code skeleton should I use for Intel 8086 DOS assembly?

Having learned Intel 8080 structure, I'm now trying to learn Intel 8086 and how the programs here are layed out. For now, it's quite intimidating even looking at the basic examples and what's worse, I can't get the difference between two ways of…
Straightfw
  • 2,143
  • 5
  • 26
  • 39
8
votes
2 answers

Use of TEST instruction with same register

Here is some C, found in a textbook I'm learning: ... do { ... n--; } while (n > 0) ... I assume n is at %edx. The assembly code produced is: testl %edx, %edx jle .L5 I understand that jle tests for less than or equal to (SF ^ OF) | ZF.…
dgamma3
  • 2,333
  • 4
  • 26
  • 47
8
votes
3 answers

How to check keys status in x86 assembly?

I took x86 assembly as a hobby this past january so I could make games that would work on old 8086-powered computers like the PCj and Tandy 1000, but the books I found don't exactly teach much on that specific topic. While some dos and bios…
DieJay
  • 95
  • 1
  • 1
  • 6
7
votes
5 answers

IDE and Assembler for 8086/88

I want to learn how to programming with assembly language for 8086/88 processor, but I couldn't find any IDE and assembler for this reason.
Hossein Mobasher
  • 4,382
  • 5
  • 46
  • 73
7
votes
1 answer

Can a UEFI machine use BIOS interrupts?

When the kernel been loaded into the memory, can it still can use BIOS interrupts? Such as mov AX,0E820h int 15h or something.
KME
  • 91
  • 2
7
votes
1 answer

What was CS register's value at boot time?

I'm a green hand to assembly language. These days I used bochs to simulate the boot procedure from virtual floppy. But one thing I don't know is what the CS register value is when the system initializes. ;; init registers org 0x7c00 BaseOfStack…
Layne Liu
  • 452
  • 5
  • 10
7
votes
1 answer

How do you disable the PC speaker beep interrupt that occurs while looping?

While executing a loop in my 8086 assembly programs, there is a keyboard key press threshold where if you press a key too many times the PC speaker will start beeping. It's obnoxious, and it slows down my programs to a crawl since the cpu has to…
bad
  • 939
  • 6
  • 18
7
votes
1 answer

Running a game written in 8086 assembly on a modern CPU

I wrote a game in assembly for the 8086 processor and run it on a DOS emulator named DOSBox. Now I want to show the game to other people without them having to download an emulator. Basically, I want to compile 8086 assembly to an executable for…
Goolmoos
  • 199
  • 1
  • 11
7
votes
1 answer

Using 3Dh causes interrupt to only return "Acces Denied"

Configuration : MS-DOS 16 BIT (writing in a .asm file, then compiling them with TASM and TLINK) Windows 7 x64 I've made a simple program in Assembly that should only OPEN a file and write a text to it. Here is the code to it: assume cs:code,…
SnuKies
  • 1,578
  • 1
  • 16
  • 37
7
votes
2 answers

How to pass/retrieve DOS command-line parameters in a 16-bit assembly program?

I am writing some little tools for MS-DOS. Now I'm writing a Shutdown.com, like for Windows XP and greater. I have already written the entire code, now I just need to pass the argument from DOS. I need to pass the parameters "-r" to reboot and "-s"…
MendaxRox
  • 101
  • 1
  • 7
7
votes
3 answers

x86 assembly: Pass parameter to a function through stack

I'm trying to make a subprogram in assembly which will draw a square on the screen. I don't think I can pass parameters to the subprogram like I would do in C++, so I figured that I could use stack to store and access the parameters (I can't use the…
sergiu reznicencu
  • 1,039
  • 1
  • 11
  • 31