An Overview of the Intel 80x86 Architecture


A Brief History of the Intel 80x86 Family -> Intel's Microprocessor Hall of Fame

Bits, Bytes and their Numbering


The Physical Structure of Memory


+----------------+
|                |  0x00000 - 0x0000F - paragraph 0 - segment 0 begins here
+----------------+                                                          
|                |  0x00010 - 0x0001F - paragraph 1 - segment 1 begins here
+----------------+
|                |  0x00020 - 0x0002F - paragraph 2 - segment 2 begins here
+----------------+
     ...

+----------------+
|                | 0x0FFF0 - 0x0FFFF - paragraph 0x0fff - segment 0 ends here
+----------------+
|                | 0x10000 - 0x1000F - paragraph 0x1000 - segment 1 ends here
+----------------+
|                |
+----------------+
    ....
+----------------+
|                | 0xFFFF0 - 0xFFFFF - paragraph 0xFFFF - segment 0xF000 ends here
+----------------+

The Logical Structure of Memory

    +-------+
    |  PSP  | program segment prefix
    +-------+ <- DS
    | Data  |
    +-------+ <- CS
    | Code  |
    +-------+
    | Stack |
    +-------+ <- SS


The Structure of the CPU


Memory Address Spaces


Intel 80x86 Instruction Format 1 - 5 bytes

The Intel 80x86 uses variable length, one address instructions. 
+--------+--------+---------+--------+--------+
|[prefix]| op-code|[Mod r/m]| [1-2 byte disp] |
+--------+--------+---------+--------+--------+
The Mod r/m byte determines the addressing mode, whether the instruction is memory to register, register to register, or register to memory and which registers are used. Pentium's add an optional SIB (Scale, Index, Base) byte after the Mod R/M (Mode, Register, Register/Memory) byte and allow 4-byte displacements.

Native date types supported are on 8-bit byte or 16-bit word integers, signed and unsigned (8086). Supports BCD arithmetic. No native floating point types or operations (optional FPU until 80486DX). ISA includes string manipulation instructions.


I/O on the Intel 80x86


Intel 80x86 and MS-DOS


Intel 80x86 Assembler Programming


The following 80x86 assembler program is a simple Hello World program. The source code begins with a Comment Header Block followed by a Data Segment, a Stack Segment, and a Code Segment.

Segments are defined by the paired directives

    name segment

    name ends

where name is chosen by the user (although we'll use data, mystack, and code to identify the data, stack and code segments)

;-------------------------------------------------------
;
;  File: Hello World
;  Name:
;  Date:
;
;  Desc : Displays "Hello World!" on screen
;
;-------------------------------------------------------
DATA SEGMENT
     Message   db 'Hello World!',0dh, 0ah,'$'
DATA ENDS
;-------------------------------------------------------
MYSTACK SEGMENT STACK 'STACK'
     db 32 DUP ('STACK   ')
MYSTACK ENDS
;-------------------------------------------------------
CODE SEGMENT
     ASSUME CS:CODE, DS:DATA, SS:MYSTACK
MAIN PROC FAR
     mov ax, data              ; Load DS with data segment address
     mov ds, ax

     mov dx, offset Message    ; Load DX with pointer to message
     mov ah, 09h               ; Invoke MS-DOS interrupt 09h
     int 21h                   ;   to display message

     mov ax, 4c00h             ; Return to MS-DOS
     int 21h
MAIN ENDP
CODE ENDS
     END MAIN


The DATA Segment : Variables and constants are declared here. The db directive (define byte) declares a variable called message containing the string "Hello World!" followed by a carriage-return (ASCII 0dh) line-feed (ASCII 0ah) combination. Strings are terminated by '$' characters (similar to cstrings which are terminated by null characters).


The STACK Segment : In the stack segment we simply allocate a block of memory for the stack.  The db 32 DUP('STACK   ') is a programming trick to allocate 32 x 8 bytes = 256 bytes of memory for a stack (the string 'STACK   ' is eight bytes long). Placing  the ASCII characters 'STACK   ' in the memory allocated to the stack has no effect on the stack but lets us see the stack under the debugger.


The Code Segment : The code goes here. Code modules are called procedures and are marked by the directives

    name proc FAR

    name endp

within the code segment. Name is chosen by the user (by convention we'll name our main procedure main).

The FAR directive refers to the fact that the program code is in a different code segment from the operating system or what ever procedure calls the program.

The main procedure must begin with the statements

    mov ax, data
    mov ds, ax

which properly initializes the DS segment register to hold the segment address of the DATA segment

The main procedure must end with the statements

    mov ax, 4c00h
    int 21h

which effects a return to the (MS-DOS?) operating system.


The Assembly and Linking Process



After creating a text file containing Intel 80x86 assembler code (a .asm file) you must assemble the source code into object code (.obj file) then link the object code to obtain an executable file (.exe). We will use Borland's Turbo Assembler (tasm) and Turbo Linker (tlink).

    +---------+
    | pgm.asm |
    +---------+
         |
         |  <- tasm (Turbo Assembler)
         |
    +---------+
    | pgm.obj |
    +---------+
         |
         | <- tlink (Turbo Linker)
         |
    +---------+
    | pgm.exe |
    +---------+
         |
         | <- to run, invoke file name pgm.exe
         |

The command to assemble a source code file is

    C:\> tasm [options] source [,object [,listing [,xref]]]

where anything in brackets is optional. The only option we need is /zi which is required for the Turbo Debugger. File extensions for source, object, listing, and xref are .asm (assembler), .obj (object), .lst (list), and .xrf (cross-reference). Tasm assumes these file extensions if no file extension is given. We will not use cross-reference files and unless you want a .lst file use the command .

    C:\> tasm /zi pgm, pgm

using no file extensions

The command to link an object code file is

    C:\> tlink [options] objectfile(s) [,exefile [,mapfile [,libfiles]]]

The only options we will use are /v which is required for the Turbo Debugger and /x to prevent the generation of a .map file. Since we will make no use of .map file or (initially) library files, use the command

    C:\> tlink /v/x pgm, pgm

Again note that we don't use file extensions.


Return to Comp 255 Home Page