This programming language may be used to instruct a computer to perform a task.
If you know 8086 Assembly, please write code for some of the tasks not implemented in 8086 Assembly.
The 8086 uses a segmented memory model, similar to the Super Nintendo Entertainment System. Unlike banked memory models used in the Commodore 64 and late NES games, segment addresses are held in segment registers. These segment registers are 16 bit and get left-shifted by 4 and added to the pointer register of interest to determine the memory address to look up. The 8086 has four in total, but only the Data Segment and Extra Segment can be used by the programmer. (The other two are reserved for the stack pointer and instruction pointer.) On the 8086, you can only load segment registers with the value in a data register, or with the
POP command. So first you must load a segment into a data register, THEN into a segment register.
;This is NOT valid code!
mov ds, @data ;you're trying to move the data segment location directly into DS. You can't!
;This is the proper way:
mov ax, @data ;I chose AX but I could have used BX, CX, or DX.
mov ds, ax ;load DS with the data segment.
There are four data registers:
DX. While most commands can use any of them, some only work with particular data registers. System calls in particular are very specific about which registers can be used for what. On MS-DOS, the
AX register is used for selecting the desired interrupt to use with the
Each data register is 16-bit, but has two eight bit halves ending in H or L, e.g.
AH, AL. Instructions can be executed using the whole register or just half of it.
mov ax, 1000h ;move 1000h into AX, or equivalently, move 10h into AH and 00h into AL.
Moving a value smaller than 16 bits into
?X is the same as moving it into
?L, and moving 0 into
?H. (? represents the data register of your choice. They are all the same in this regard.)
;is the same as:
mov al, 30h
mov ah, 0h
Generally speaking, the 8086's registers serve the following purposes:
AXis the "Accumulator" and is used for advanced mathematics routines, as well as the source/destination for the
LODSWcommands when loading/storing bytes from consecutive regions of memory.
BXcan be used as a variable offset on the Source Index/Destination Index registers (more on those later).
CXis used as a loop counter. The
JCXZcommand jumps to the specified address, but only if
CX = 0.
DXcan be used to specify a shift amount when bit shifting. Later versions of the x86 family allow this to be an arbitrary immediate value, but on the original 8086 you can only specify 1 or
When writing to or reading from consecutive sections of memory, it is helpful to apply an offset from a base value. The Base Pointer register
BP, Source Index
SI, and Destination Index
DI can point to various regions of memory. Many commands that work with these registers can auto-increment or decrement them after each load or store. In addition, they can be optionally offset by a constant, or the value stored in
BX. Unlike the data registers,
SI cannot be split in half and worked on separately. Only data registers allow you to work in 8-bit.
As with Z80 Assembly, you can't push 8-bit registers onto the stack. For data registers, you have to push/pop both halves.
;This is valid code.
;This is NOT valid code.
As with all processors that use a stack, if you push one or more registers and want to restore the backed-up values correctly, you must pop them in the reverse order. You can pop them out of order on purpose to swap registers around. In fact, this is a quick way to move the segment from
ES, or vice-versa:
pop ES ;you can't do "mov es, ds" but you can do this!
The 8086 has a lot of advanced mathematics commands. Like the 68000 it can multiply and divide. Although the 8086 doesn't work with 32 bit numbers in a single register, it has many more options for Binary Coded Decimal values, including commands for both "packed" (two digits per byte) and "unpacked" (one digit per byte.) By contrast, 68000 Assembly only has commands for the "packed" format.
- 'Akuyou', Keith. Learn Multiplatform Assembly Programming with Chibiakumas! Las Vegas, NV. Self-published, 05 April 2021.
This category has the following 3 subcategories, out of 3 total.
Pages in category "8086 Assembly"
The following 95 pages are in this category, out of 95 total.
- Show ASCII table
- Sierpinski triangle
- Sierpinski triangle/Graphical
- Sieve of Eratosthenes
- Split a character string based on change of character
- Square but not cube
- Start from a main routine
- Stern-Brocot sequence
- Strip a set of characters from a string
- Strip control codes and extended characters from a string
- Sum digits of an integer
- Sum of squares