assemblyx86-16forward-referencea86

A86 - definition conflicts with forward reference


I'm trying to use A86 to assemble some code for 8086. I narrowed my problem down to 4 lines of code.

MOV BX, testz
ADD AL, [testz]

INT 20h
testz:
~     ^
#ERROR 16: Definition Conflicts With Forward Reference                    @@@@#
db ?

What do you think is wrong with this code? I am moving the address itself to BX register and adding the byte-value in the testz address to AL.

In a bigger program I also get #ERROR 13: Byte/Word Combination Not Allowed.

But label is a word where [label] is a byte. Why can't my compiler differentiate between those?

ADD BL, [second]
MOV BX, second
~             ^
#ERROR 13: Byte/Word Combination Not Allowed   
second:
~      ^
#ERROR 16: Definition Conflicts With Forward Reference                    @@@@#
db ?

Because I can't see any Byte/Word conflict.


My compiler interprets offset testz and testz equally. I looked at the bytecodes and couldn't see any difference.

MOV BX, testz
ADD AL, [BX]

The code above works, but is there any other way that I can do this in one line like

ADD AL, [testz]

Whenever I put a label name in [], it is just not acceptable according to my compiler a86. But I feel they are allowed in the language.


Solution

  • I suspect you want MOV BX, offset testz. It appears that your assembler interprets [testz] and testz to mean the same thing.

    You might confirm this by trying instead the notionally equivalent LEA BX, testz

    EDIT: (from http://www.csn.ul.ie/~darkstar/assembler/manual/a14.txt):

    ERROR 16: Definition Conflicts With Forward Reference
    
       This error occurs when the assembler has previously guessed
       the type of a forward-referenced symbol in order to determine
       what kind of instruction to generate, and the guess turned out
       to be wrong.  The error is reported at the time the symbol is
       defined.  For example, when A86 sees MOV AX,FOO, it will
       assume FOO is an immediate value.  This error is reported if
       FOO turns out to be a word variable: FOO DW 0.  You need to
       search backwards from the error message, to references of FOO,
       and specify the type you intend to be used: MOV AX,FOO W.  If
       you really did intend to load the offset of FOO and not the
       memory contents, you can code MOV AX,OFFSET FOO to make the
       error message go away.