Search code examples
assemblyx86fasm

Doesn't compile Assembly directivies


Im using Flat Assembler, and when I want to run something, it writes: " illegal instruction" to every line of the assembler directives. For example in the code below, it would write that .MODEL SMALL is not legal, and if id delete this line it would write that .STACK 200H is not legal and so on.

.MODEL SMALL
.STACK 200H
.DATA

.CODE
start:
    mov ax, @DATA
    mov ds, ax

    mov ax, 4c00h
    int 21h

END start

and for this code it works:

start:
    mov ds, ax

    mov ax, 4c00h
    int 21h  

Solution

  • There is no one single standard about the directives of the different assemblers. There are many of them.

    The directives of FlatAssembler (FASM) are described in details in FASM programmer's manual, which is located on public and accessible web page.

    Also, this manual should be provided for you in the downloaded package as PDF or TXT file, depending on the target OS of the package.

    It covers all assembler directives and supported instructions. There are also, many examples and if something is still not clear, you can ask on FlatAssembler message board.

    In the case of the questioned code, FASM code will look like this:

    format MZ
    entry _CODE:start
    stack 200H
    
    segment _DATA
    
    segment _CODE
    
    start:
        mov ax, _DATA
        mov ds, ax
    
        mov ax, 4c00h
        int 21h
    

    But, considering that this program is too simple to be compiled to MZ executable (which is suitable for applications with code+data bigger than 64Kbyte) I would suggest more simple COM file format to be used:

        org 100h
    
        mov ax, 4c00h
        int 21h