What code skeleton should I use to build Intel 8086 DOS?

Having learned the structure of the Intel 8080, I am now trying to study the Intel 8086 and how the programs are laid out here. This is pretty intimidating at the moment, even looking at the basic examples, and even worse, I can't get the difference between the two ways I wrote the code for 8086 that I came across. Namely, sometimes I see:

.model small .stack 100h .code start: mov dl, 'a' ; store ascii code of 'a' in dl mov ah, 2h ; ms-dos character output function int 21h ; displays character in dl register mov ax, 4c00h ; return to ms-dos int 21h end start 

So far I have also found:

 Progr segment assume cs:Progr, ds:dataSeg, ss:stackSeg start: mov ax,dataSeg mov ds,ax mov ax,stackSeg mov ss,ax mov sp,offset top mov ah,4ch mov al,0 int 21h Progr ends dataSeg segment dataSeg ends stackSeg segment dw 100h dup(0) top Label word stackSeg ends end start 

Obviously, I know that the two do very different things, but what puzzles me is how different the general syntax is. In the latter case, we have some "segment", while in the first it is simply .model, .stack and .code (and sometimes .data, from what I found). Is there any difference? Can I choose which one suits me? The former looks much easier to understand and clarify, but can I use it instead of the latter?

+8
assembly x86 dos x86-16
source share
1 answer

It depends on the operating system you are targeting (or either the BIOS or bare metal), the format you are looking for, and the assembler you are using.

The first example that you published for MS-DOS.COM programs, the second for MS-DOS.EXE programs, and I assume that both of them use Microsoft® assembler.

If you want to use the GNU assembler (for example, on MirBSD or GNU / Linux) for the i8086 MS-DOS.COM target programs, you can use this:

  .intel_syntax noprefix .code16 .text .globl _start _start: mov ah,9 mov dx,offset msg int 0x21 /* exit(0); ← this is a comment */ mov ax,0x4C00 int 0x21 msg: .ascii "Hello, World!\r\n$" 

Compile this file ( hw.S ) with

 $ gcc -c -o hw.o hw.S $ ld -nostdlib -Ttext 0x0100 -N -e _start -Bstatic --oformat=binary -o hw.com hw.o 

I tested the result in DOSBOX under MirBSD / i386 and looked at it in hexdump to see if it is correct.

Unlike other solutions, you do not define the source (org) in the assembly file, but on the linker command line (ld) here.

Ive also got an example intended for the raw x86 BIOS and one more (bootsector for blocklisters) and one more (bootsector for * .tar archives) if you are interested; they need different sources and they need an i386 processor, although they only use 16-bit mode.

You cannot make * .EXE files this way.

ELKS is also an interesting goal for the i8086, but I haven't done anything with it yet. Make sure you get GNU as a new version to know .intel_syntax noprefix mode.

+3
source share

All Articles