CSE3101 Assembly Language Introduction

Why use assembly language?

Intel architecture history

Reference

IA-32 Architecture

General purpose registers

  
  31         16 15  8 7   0
  +------------+-----+-----+
  |    EAX     | AH  | AL  |  Accumulator (EAX = 32 bits, AX = 16 bits, AH, AL = 8 bits)
  +------------+-----+-----+
  |    EBX     | BH  | BL  |  Table base
  +------------+-----+-----+
  |    ECX     | CH  | CL  |  Counter
  +------------+-----+-----+
  |    EDX     | DH  | DL  |  High bits of AX, EAX
  +------------+-----+-----+
  |    ESI     |    SI     |  Source index
  +------------+-----------+
  |    EDI     |    DI     |  Destination index
  +------------+-----------+
  |    EBP     |    BP     |  Base pointer
  +------------+-----------+
  |    ESP     |    SP     |  Stack pointer
  +------------+-----------+
Important flags (1 bit): Other registers:

Real mode

Protected mode (preferred) Real mode and protected mode opcodes differ. You must tell your compiler or assembler which kind you want.

Program organization

Windows .EXE 32-bit (flat model)


 0ffffffffh  +-------------+  <-- SS limit
             |             |  <-- ESP
             |   Stack     |
             |             |
             +-------------+  <-- SS base
             |             |
             |             |
             +-------------+  <-- DS, ES, FS, GS limits
             |  Dynamic    |
             |  data       |
  +-------+  +-------------+
  |       |  |  Static     |
  | .exe  |  |  data       |
  |       |  +-------------+  <-- DS, ES, FS, GS bases
  | File  |  |             |  <-- CS limit
  |       |  |  Code       |
  |       |  |             |  <-- EIP
  +-------+  +-------------+  <-- CS base
             |             |
         0h  +-------------+ 

MSDOS .EXE 16-bit (large model)


    0fffffh  +-------------+  <-- SP
             |             |
             |   Stack     |
             |             |
             +-------------+  <-- SS
             |             |
             |             |
             +-------------+
             |  Dynamic    |
             |  data       |
  +-------+  +-------------+
  |       |  |  Static     |
  | .exe  |  |  data       |
  |       |  +-------------+  <-- DS, ES
  | File  |  |             |
  |       |  |  Code       |
  |       |  |             |  <-- IP
  +-------+  +-------------+  <-- CS
             |             |
         0h  +-------------+

.COM 16-bit (tiny model)

 0ffffh +------------+
        |            | <-- SP (stack grows downward)
        | free       |
        | memory     |
        |            |
        +------------+
        | copy of    |
        | prog.com   |
  100h  +------------+  <-- IP (instruction pointer)
   80h  |  PSP       |  <-- (command line arguments at 80h)
   0h   +------------+  <-- CS, SS, DS, ES

Software development