assemblywindows-10nasmassemble

Nasm error; undefined labels


This period of time I am trying to learn assembly. I used the ms-dos "debug" command to create simple programs but now I want to make large programs. I downloaded nasm and tried to assemble the following code:

.model small
.code
    mov ax, bx

But in the labels .model and .code it says that they ar undefined. I tried this again in a couple of other assemblers and the same thing has happened. Can anyone help me with this problem? I am using Windows 10.


Solution

  • Nasm syntax for your program:

    segment code 
    ..start: 
    mov ax, bx
    

    special symbol ..start marks the entry point to your program. Here is a nice manual on writing 16-bit code in Nasm

    Regarding .model small - there are no memory models in Nasm, citate from documentation at http://www.nasm.us/doc/nasmdoc2.html:

    NASM also does not have any directives to support different 16-bit memory models. The programmer has to keep track of which functions are supposed to be called with a far call and which with a near call, and is responsible for putting the correct form of RET instruction (RETN or RETF; NASM accepts RET itself as an alternate form for RETN); in addition, the programmer is responsible for coding CALL FAR instructions where necessary when calling external functions, and must also keep track of which external variable definitions are far and which are near.

    And I suggest you to read Nasm documentation - there are answers to most of your questions.