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

How do I change the designs of ascii codes in 8086 assembly?

Im trying to redefine how the characters will look (in this case according to the Hebrew alphabet). In this segment I wanted to change 'k' (ascii 6bh) to resemble this ל. .model small .stack 200h ;data segment containing all of the variables used…
wew84
  • 11
  • 2
1
vote
1 answer

Find the two largest numbers passed on the stack and multiply them, return DX:AX pair

I have an assignment where we are passed 4 values on the stack (v1, v2, v3, v4), are to find the two largest values out of the four, and then multiply them together to return the DX:AX pair. This is the code that I have come up with so far,…
CadetFayed
  • 67
  • 3
  • 10
1
vote
1 answer

assembly macro for adding two 64bit numbers on a 32bit machine

I need to write a macro for adding 2 64bit on a 32bit machine. One way I thought about is as follows: %macro add_double 2 mov edx, %1 add %2,edx mov edx,%1 shl edx,31 mov eax,%2 shl eax,31 add eax,edx add %2,eax %endmacro will this even work?…
Tai
  • 59
  • 5
1
vote
1 answer

Assembly (emu8086) not allowing moving of bytes into 8-bit registers

I am making a calculator-type program, and I use this to get a number from the user and store it: mov ah, 01h int 21h mov offset num1, al and at the end of the code I have num1 set up as a byte with num1 db 0 giving it a default value of 0. The…
DrVanYoshi
  • 11
  • 2
1
vote
4 answers

physical address formula in 16 bit real mode: why multiply segment by 16?

physical address=16*selector+offset but i don't know why multiplying 16 by selector?
sia
  • 401
  • 3
  • 8
  • 20
1
vote
1 answer

What does DX + 2 mean in mov ah,9 int 21h?

mov dx, offset buffer mov ah, 0ah int 21h jmp print buffer db 10,?, 10 dup(' ') print: xor bx, bx mov bl, buffer[1] mov buffer[bx+2], '$' mov dx, offset buffer + 2 mov ah, 9 int 21h I know buffer[bx+2] stands for '$', but offset buffer +2 in mov…
BeGood
  • 191
  • 2
  • 9
1
vote
2 answers

Flags on Instruction pointer overflow in 8086/8088

Hey guys, Im new to the 8086 architecture and have not been able to find much on Google related to the following: On the i8086 or i8088 (ie 16bit, segmented addressing) what happens if an instruction fetch occurs with the instruction pointer…
1
vote
1 answer

How to convert binary into decimal in assembly x8086?

I find some code really works, but I don't know why this code works. why combining RCL and ADC could convert the binary to decimal, is this algorithm a nice one? how to explain this, are there any better code? ;input=R5R6R7 ;output=buffer0 -…
igonejack
  • 2,366
  • 20
  • 29
1
vote
2 answers

converting a vector of chars to int in assembly

I'm trying to do the following, but I'm having some trouble, and the only code I find on the web is for transforming strings into a number (basicly atoi), but I need something slightly different, e.g: num1 Db '60','30' num2 Db '2', '3' num3 Db '*',…
Zetsuno
  • 97
  • 1
  • 9
1
vote
1 answer

Validate maze in Assembly 8086

I'm creating a maze game in emu8086, but I have a problem. The asterisk is the character and the "1" are the walls. How to validate if the asterisk is positioned on "1"?, the validation should do that when I move the arrow left , right, up or down,…
alex22596
  • 13
  • 4
1
vote
1 answer

Calculating ABSOLUTE ADDRESS / Registry values in Assembler (Intel 8086)

I know the ABSOLUTE ADDRESS of the next instruction is located 50000 (hex), and I know that the hex value that should be in the IP Register is 4000 (hex). My question is... Why does it work like this? I have the other registry values available if…
Raven Dreamer
  • 6,940
  • 13
  • 64
  • 101
1
vote
1 answer

Using cmpsb in assembly

I have been struggling to understand how cmpsb works in assembly, as I am trying to do a program that compares an input string which I supposedly saved in a variable with a string that is already defined in another variable, and if both are the same…
1
vote
1 answer

Print the HEX ASCII equivalent of a Alphanumeric character on the screen using Assembly language

So my doubt is why are we using ADD AL,07H if AL contains something greater than 10? What's the explanation for ADD AL,07. Here is the code. MOV AH,01H ;TAKE INPUT INT 21H MOV BL,AL ; SAVE VALUE OF AL, SO THAT IT CAN BE USED LATER MOV…
Khacho
  • 199
  • 3
  • 16
1
vote
1 answer

cannot evaluate this expression?

I Have a Problem With my Assembly Program and i have a unknown error for myself ! after i wrote this code : codesg segment para 'code' assume cs:codesg, ds:codesg, ss:codesg org 100h Begin : jmp main Text1 db ' ali ahmadi ' , '$' …
Rastin Radvar
  • 143
  • 1
  • 1
  • 8
1
vote
1 answer

Coverting Assembler (8086) Command Into Machine Code

I need to translate the Assembler command MOV BL,[ALPHA] into machine code of intels 8086 processor. Therefore, ALPHA is an 1 Byte variable at the 11th Position of the Data Segment, which is already loaded in the DS Register. I already translated…
Ba5t14n
  • 719
  • 2
  • 5
  • 20