Search code examples
assemblycompiler-errorsdosx86-16tasm

Assembly program compilation error


I have a problem with following 16-bit TASM program which evaluates the expression (ab+cd)/(a-d):

MyCode          SEGMENT     

            ORG      100h
            ASSUME  CS:SEGMENT MyCode, DS:SEGMENT MyCode, SS:SEGMENT

Start:
            jmp      Beginning

a               DB      20
b               EQU     10
c               DW      5
d               =       3
Result          DB      ?

Beginning:
            mov     al, a    
            mov     bl, b    
            mov     dx,ax    
            mov     al, BYTE PTR c    
            mov     bl, d    
            mul     bl        
            add     dx,ax   
            mov     al, a     
            sub     al,bl    
            mov     bl,al    
            mov     ax,dx    
            div     bl        

            mov     Result, al 

            mov     ax, 4C00h
            int     21h

MyCode          ENDS

            END Start

The compilation errors I get in DOSBox console state that there's an undefined symbol (SEGMENT) and that the compiler can't address with currently ASSUMEd segment registers. It seems to me that that I'm missing the definition of a block, but I have no idea how to proceed further. What's wrong with this code?


Solution

  • I won't fix the logical errors for you, but the syntax in the top of this code is incorrect:

    MyCode          SEGMENT     
    
                ORG      100h
                ASSUME  CS:SEGMENT MyCode, DS:SEGMENT MyCode, SS:SEGMENT
    
    Start:
    

    You don't use the directive SEGMENT in the assume, they have to be removed. When removed the segments have to have a name applied to them. One is missing on SS:. It should look like:

    MyCode          SEGMENT
    
                ASSUME  CS:MyCode, DS:MyCode, SS:MyCode
                ORG      100h
    
    Start:
    

    In DOS COM program all the segments for DATA, CODE, and the STACK are in the same segment. You can also achieve the same by replacing it with:

    .model tiny
    .code
    ORG 100h
    Start:
    

    The TINY model is designed to work for DOS COM program creation. The ORG 100h directive has to be preceded by the .code directive. With this modification you have to remove this line:

    MyCode          ENDS