Search code examples
assemblyemu8086

Duplicate Declaration of Data in .MODEL SMALL Assembly


I am new to assembly language and am trying to create a simple program to add numbers in assembly language. I did succeed in launching the program when the .MODEL is Tiny, but the program returns "Duplicate Declaration" error when .MODEL was changed to small.

I understand the definition of both model, yet i fail to figure out what changes.

What I did try :

  • I changed the data name to data1 and it works in SMALL but not in TINY.
  • I added the code .org 100h after .MODEL and it works, because it made the program run in near memory(?)

What concept am I missing?

Thank you in advance

    .MODEL TINY

.DATA
data DB 10D, 11D, 12D, 13D, 14D, 15, 16D, 17D, 18D, 19D
.CODE
.STARTUP
XOR AX, AX
MOV BX, OFFSET data
MOV CX, 5
ulang:
ADD AX, [BX]
INC BX
LOOP ulang
.EXIT
END

Screenshot of the error and the code.


Solution

  • The problem is that the data segment also has a symbol name which is - surprisingly - DATA.

    In other words:

    The assembler implicitly puts symbols after the starts of the segments. You write:

    .DATA
    ...
    .CODE
    ...
    

    ... and the assembler implicitly does something like:

    .DATA
    DATA:
    ...
    .CODE
    CODE:
    ...
    

    ... so the label DATA: is defined twice if you use it in your code!

    Note that you cannot "just" juse these labels generated implicitly so you have to use another name like DATA1.

    I did succeed in launching the program when the .MODEL is Tiny

    Not absolutely sure but in "tiny" memory model the "implicit" labels I'm speaking about are not needed. Maybe the assembler will simply not create such labels when using the "tiny" memory model.