Search code examples
assemblyx86-16tasm

How can a (local) label end outside it's own segment (TASM 8086)?


My professor often uses this pattern of writing his code where DS is involved.

ASSUME CS:CODE,DS:DATA

DATA SEGMENT
[...]
DATA ENDS

CODE SEGMENT
START:
[...]
CODE ENDS
END START
END

According to his concept, we do this so that the assembler checks for the data segment. But I can't really agree on it without a valid explanation...

How does a label end outside a segment?

Why can't the assembler check for the DS without it?

Are labels in assembly different?


Solution

  • END START isn't "the end" of the start label. Labels themselves don't have ends or lengths or scopes. (Use proc foo / endproc for that, unless that's only MASM not TASM).

    END START is the end of the whole asm file (parsing stops after that). END label also sets the entry point = the specified label. It's a weird name for a directive with that purpose, but TASM is very old.

    (The assembler can put metadata in the .obj file to tell the linker the entry point symbol name, if the assembler doesn't emit a .exe directly.)


    Think of labels as zero-width tags that you can reference from elsewhere, nothing more.

    If you have a block of code for a function you want to call, you stick a label right before it so you can call to that point. The machine code for that function has some size, but the label doesn't; it's merely labeling the start of the block. (So a label always has exactly 1 address.)