III.7 Segment Type

Every assembly time expression is assigned a segment type, depending on its operands and operators. The segment type indicates the address space, the expression result might belong to, if it were used as an address. There are six possible segment types:

CODE
DATA
IDATA
XDATA
BIT
NUMBER     (typeless)

Most expression results have the segment type NUMBER. That means they are assumed to be typeless. However, in some cases it may be useful to assign a particular segment type! The following six rules apply when the segment type is evaluated:

  1. Numerical constants are always typeless.
    Consequently their segment type is NUMBER.
     
  2. Symbols are assigned a segment type during definition. Symbols that are defined with EQU or SET have no segment type. Labels get the segment type of the currently active segment.
     
  3. The result of a unary operation (+, -, NOT, HIGH, LOW) will have the segment type of its operand.
     
  4. The results of all binary operations (except “+”, “-” and “.”) will have no segment type.
     
  5. If only one operand in a binary “+” or “-” operation has a segment type, then the result will have that segment type, too. In all other cases, the result will have no segment type.
     
  6. The result of the bit operation “.” will always have the segment type BIT.


Examples:

The following symbols have been defined in a program:
        OFFSET  EQU   16
        START   CODE  30H
        DOIT    CODE  0100H
        REDLED  BIT   P1.3
        VARIAB4 DATA  20H
        PORT    DATA  0C8H
        RELAY   EQU   5
1.)The expressionSTART+OFFSET+3will have the segment type CODE.
2.)The expressionSTART+DOIT will be typeless.
3.)The expressionDOIT-REDLED will be typeless.
4.)The expression2*VARIAB4 will be typeless.
5.)The expressionPORT.RELAY will have the segment type BIT.

The segment type is checked, when expressions appear as addresses. If the expression result is not typeless and does not have the segment type of the corresponding segment, the instruction is flagged with an error message.
The only exceptions are the segment types DATA and IDATA, which are assumed to be compatible in the address range of 0 to 7FH. Since ASEM-51 does only support absolute segments, those addresses are really always pointing to the same physical location in the internal memory.


Example:

Line  I  Addr  Code            Source

   1:          N        30             DSEG AT 030H     ;internal RAM
   2:      30  N        01     COUNT:  DS 1             ;counter variable
   3:
   4:                                  CSEG             ;ROM
   5:    0000  C2 30           START:  CLR COUNT
                                                ^
                         @@@@@ segment type mismatch @@@@@

The CLR instruction is flagged with the error message “segment type mismatch” in the assembler list file, because only a BIT type address is allowed here. However, COUNT is a label with the segment type DATA!