Programming Format and Global Structure

General Format

- though the assembler language is freeform like C, we adhere to a standard format for clarity
- general form of the lines of a program are denoted by fields

LABEL       FIELD2      OPERAND(S)  ; comment
|           |           |           |
           Convenient tab stops
LABEL Field

Form:

<label>     <pseudo-instruction/assembler directive>

-or-

<label>:    <instruction>
FIELD2 Field

Contains:

  1. pseudo-operations (assembler directives)
    non-executable used by assembler
    not translated into machine code
    UPPERCASE convention
  2. executable operations (opcodes)
    converted to machine code
    1 opcode per line with 0+ operands
    lowercase convention

Global Structure

segments in an assembly program: STACK, DATA, CODE

Form:

<name>      SEGMENT     <option1>       <option2>  ...  <optionN>
.
.
.
<name> ENDS
The Stack Segment

example:

StackSeg    SEGMENT     STACK       para        'STACK'
            DB          32          DUP("STACK**")
StackSeg    ENDS

Option 1 - STACK
Must contain STACK so it can be combined with other stack segments by the assembler.

Option 2 - para
Sets the kind of address at which hte physical address begins.
para is default

Option 2 - 'STACK'
Assigns the stack a name used by a debugger
Optional, not always used.

Shortcut definition

.STACK N

Where N is the number of bytes to reserve. All defaults are used.

The Data Segment

example:

DatSeg      SEGMENT     para    'DATA'
.
.
.
DatSeg      ENDS

Shortcut definition

.DATA
The Code Segment

example:

CodeSeg     SEGMENT     para    'CODE'
            ASSUME  ss: StackSeg    ...
.
.
.
CodeSeg     ENDS

There are 14 segment registers on the 8086

  1. cs - pointer to active code segment
  2. ss - pointer to active stack segment
  3. ds - pointer to active data segment
  4. es - pointer to active extended segment

The last line ends with:

        END     <startlabel>

example:

program:
.
.
.
        END     program

Defining Data and Variables

The CODE Segment

Interrupts/DOS Calls

Return to CSC2252

Copyright © 1999, Bruce Lin