CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

The Assembly Process


  1. Compilers and Assemblers
  2. The Assembly Process
  3. Small Assembly Sample
  4. MASM Command Line Interface
  5. Assembling
  6. Linking
  7. Loading
  8. Useful Tools and Utilities

1. Compilers and Assemblers


2. The Assembly Process


  1. Assembling the source code into an object file

  2. Linking the object file with other modules or libraries into an executable program

  3. Loading the program into memory

  4. Running the program

  •   assembler translates instruction into object code

  •   what the assembler does

3. Small Assembly Sample


     
     ; add_16_bytes.asm
     ;
     .586P
     ; Flat memory model, standard calling convention:
     .MODEL FLAT, STDCALL 
     ;
     ; Data segment
     _DATA SEGMENT
         values db 16 DUP( 5 ) ; 16 bytes of values "5"
     _DATA ENDS
 
     ; Code segment
     _TEXT SEGMENT
     START:
         mov eax, 0      ; clear result 
         mov bl, 16      ; init loop counter 
         lea esi, values ; init data pointer
     addup:
         add al, [esi]   ; add byte to sum
         inc esi         ; increment data pointer 
         dec bl          ; decrement loop counter 
         jnz addup       ; if BL not zero, continue
         mov [esi], al   ; save sum 
         ret             ; Exit
     _TEXT ENDS
 
     END START
     
 

4. MASM Command Line Interface


5. Assembling


  • At assembly time, the assembler:

    • Evaluates conditional-assembly directives, assembling if the conditions are true.

    • Expands macros and macro functions.

    • Evaluates constant expressions such as MYFLAG AND 80H, substituting the calculated value for the expression.

    • Encodes instructions and nonaddress operands. For example, mov cx, 13; can be encoded at assembly time because the instruction does not access memory.

    • Saves memory offsets as offsets from their segments.

    • Places segments and segment attributes in the object file.

    • Saves placeholders for offsets and segments (relocatable addresses).

    • Outputs a listing if requested.

    • Passes messages (such as INCLUDELIB) directly to the linker.

  •   translating a single assembly module

6. Linking


  • Once your source code is assembled, the resulting object file is passed to the linker. At this point, the linker may combine several object files into an executable program. The linker:

    • Combines segments according to the instructions in the object files, rearranging the positions of segments that share the same class or group.

    • Fills in placeholders for offsets (relocatable addresses).

    • Writes relocations for segments into the header of .EXE files (but not .COM files).

    • Writes the result as an executable program file.

      Linking multiple object files together

  •   The assembler and linker

7. Loading


8. Useful Tools and Utilities