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
1
vote
4 answers

Changing the sign bit of a register in assembly 8086

I'm trying to write assembly code that does a fairly simple thing, it changes the sign bit (just the sign bit) of the register AL. I need to find two different ways to do this, but sadly the solutions I came up with don't seem to be working. 1) I…
Oria Gruber
  • 1,513
  • 2
  • 22
  • 44
1
vote
1 answer

stack Label in 8086 assembly instruction set

I am trying to learn 8086 assembly. this is the stack part of a 8086 assembly code : STACK SEGMENT STACK DW 50 DUP(?) TOP_STACK Label Word STACK ENDS what is the purpose of TOP_STACK Label Word ? i couldn't find Label keyword in 8086…
user175023
  • 135
  • 7
1
vote
0 answers

idiv instruction in assembly 8086

I'm trying to find the value of AX. AX = (DX AX) / operand DX = remainder (modulus). All the values are in hexademical mov CX, 80A2 mov AX, DD38 mov DX, 49 idiv CX add AX, DX AX-? What am I doing wrong? This is what I do: AX = 0049 DD38 / 80A2 =…
1
vote
2 answers

Mouse in Assembly 8086

As part of a school project I am making a game that shows everything we've learned this semester. So I made this game where you're this smiley guy and you run around a maze with obstacles that bring you back to the start of the maze and once you…
itamar reif
  • 139
  • 2
  • 9
1
vote
1 answer

String Arrays in Assembly 8086

As part of a school project (majoring in Computer Science and we learn assembly language for part of our grade, starting with 8086 right now) I have to make... something using what we've "learned" (our teacher gave us a list of commands and told us…
itamar reif
  • 139
  • 2
  • 9
1
vote
2 answers

print string with bios interrupt 0x10

I want to print a string using bios interrupt 0x10. But I get only a blue fiel, without letters in it. Maybe I habe a problem by adressing my string. Edit: I have two code files. The first is written on the first sector of a floppy. It copys the…
spitzbuaamy
  • 751
  • 2
  • 10
  • 25
1
vote
2 answers

how to store strings in 8086

Im using emu8086. For example i have a macro called 'store' which takes a string and stores it in an array, how do i do that? sample code: arrayStr db 30 dup(' ') store "qwerty" store MACRO str *some code here which stores str into…
ryuuuuuusei
  • 98
  • 5
  • 22
1
vote
2 answers

Algorithm for Trap Flag in 8086

Is there any algorithm to set or clear TF? For example for ZF flag, we can making situation for set or clear it by adding two number that result is zero...
mohammadrezamajd
  • 149
  • 1
  • 11
1
vote
1 answer

assembly 8086 adding a space in a string

I ran into a problem in my program. Basically what i want to do check if there is a space after a dot in a string and if there isn't i add a space right after the dot. However i don't get how to go about this since my buffer is limited size,…
Dominykas Ber
  • 49
  • 1
  • 8
1
vote
1 answer

NASM and a question about ADC - ASM 8086

I study assembly on High-school and I would like to try to make assembly programs at home. I downloaded NASM but I don't understand how to run the .s files with it - if you can write a simple way here to run it I'd glad :-) and in addition I have a…
Tal
  • 303
  • 1
  • 6
  • 11
1
vote
0 answers

REPE CMPSB problems

i'm trying to use rep cmpsb as following: DSEG SEGMENT PARA PUBLIC 'DATA' SOURCE DB 'ASDF' TARGET DB 'ASDF' SIZE EQU ($-TARGET) DSEG ENDS SSEG SEGMENT PARA STACK 'STACK' SSEG ENDS CSEG SEGMENT PARA PUBLIC 'CODE' …
Yasmin
  • 343
  • 3
  • 18
1
vote
1 answer

How to compare two strings in assembly?

I'm new in assembly. I want to compare two string using "cmps". I read some examples and I write this : GETSTR MACRO STR MOV AH,0AH LEA DX,STR INT 21H ENDM PRINTSTR MACRO STR MOV AH,09H LEA DX,STR INT 21H ENDM EXTRA SEGMENT …
zahra
  • 97
  • 2
  • 10
1
vote
0 answers

phase error between passes 8086 assembler

"phase error between passes error" is reported when I try to assemble my program using 8086 macro assembler. I have defened various macros in macros.asm file and wrote a test.asm file to test my program. When execute masm test.asm; command, phase…
Vineel
  • 436
  • 6
  • 12
1
vote
1 answer

Why is the variable value not moving into the register?

I am embarking on the journey of learning assembly language. I am using emu8086 to practice. I have run into a small problem that I can't seem to figure out though--likely due to lack of knowledge in assembly. I just want to move the value of the…
Crimsus
  • 13
  • 1
  • 4
1
vote
2 answers

output byte value in assembler

I'm a bit ashamed about asking this, but how do i output the value of a byte in assembler? Suppose I have the number 62 in the AL register. I'm targeting an 8086. There seem to be available only interrupts that output it's ascii value. Edit: Thank…
Valentin Brasso
  • 1,388
  • 7
  • 21
  • 41
1 2 3
99
100