Skip to content

Assembly Language: x86 family of Intel processors

Assembly Language(ASM) the lowest level language after binary encoding. It does not see any widespread usage anymore because of the complication and non-portability. ASM is still being used when it comes to write low level programs like boot-loaders and device driver. ASM compromise of Instruction mnemonics that are defined within the Processor (CPU) known as instruction Set. We will only discuss about the x86 Intel processor family for their 32-bit support. Let’s start looking into these Instruction sets.

Intel X86 Processor family

The processors of this family have same features and almost identical instruction sets. Lets see them in little detail :

  1. 8086 : It provide several 16-bit registers: AX, BX, CX, DX, SI, DI, BP, SP, CS, DS, SS, ES, IP and FLAGS. They only support 1MB of memory and only operate in real mode. Therefore any program may access any memory address, even the memory of other programs. The programs can be divided into segments and each segment can not be bigger then 64K.
  2. 80286 : It is almost same as 8086 processor just with a support for protected mode. Which in result put a restriction that amy program cannot access the memory address of the other programs.
  3. 80386 : It extended the registers to contain 32-bits: EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP etc. Also added 2 new 16-bit registers FS and GS. It also supports protected mode. But one more major change was the memory it can access. It can now access 4GB of memory and also each segment can be of 4GB.
  4. 80486 : It didn’t add many new features just speeds up all the processing. This family is also almost identical to Pentium and Pentium Pro. And then came the Pentium MMX which just added support for the graphics support into the processor and Pentium II which is Pentium Pro plus MMX support.

Details on registers:

16-bit registers(8086 – 80286):

There are 4 16-bit general purpose registers: AX, BX, CX and DX. Each register can be divided into 2 8-bit registers, e.g. AX can be divided in AH(higher 8-bits of AX) and AL (lower 8-bit of AX).

NOTE: altering the value of AX will result in altered value of AH and AL and vice verse.

It also have 2 index registers SI and DI, often used as pointers but can be used as general purpose registers. But these registers cannot be divided into 8-bit registers like general purpose registers. there are two pointer registers the points to data or base, BP and stack, SP. Then comes the segment registers, there are 4 of them: CS, DS, SS and ES as code segment, data segment, stack segment and extra segment respectively. Finally comes the Instruction Pointer, IP which is used with CS to keep track of the addresses that holds the instructions that needs to be executed and FLAGS, that hold special value. Every bit of FLAGS register defines what needs to be done while executing or after execution.

32-bit registers(80386 – present):

32-bit registers are nothing but extended registers which were present in 8086 thus they can now hold 32 bits rather 16 bits. All the registers that are extended has ‘E’ suffix in their name. The new general purpose registers are : EAX, EBX, ECX and EDX. We can still use lower 16 bits of these processor by calling AX, BX and so on. Which can further be divided into 8-bit registers same as in 16 bit registers but there is no way to access only higher 16 bits of extended general purpose registers. Index registers are also extended to ESI and EDI. Other extended registers were EBP, ESP, EFLAGS AND EIP. 32-bit protected mode can use only extended versions of these registers. There are new segment registers FS and GS which are just extra segment registers like ES and doesn’t hold any meaning.

Details on Modes Available

Real Mode

In real mode valid address mode is from (0000)16 to (FFFF)16. In this mode the max memory that can be accessed is 1 MB.

This require 20 bits to store the address that cannot be stored in a 16 bit address. so this is done by using two 16 bit registers. first one as selector and second one as offset. so the actual address is 16*selector + offset e.g.

then actual address will be:

Selector value can only reference 64K of memory i.e the max address can be referenced by 16 bit address which is 2^16 = 64k(MAX size of the segment).
The program and its data can be bigger then 64K thus it needs to be split into more segments of size equal or less then 64K. (I know its ugly!).

Protected Mode

16-bit Protected Mode

In protected mode the access method is completely different from the real mode’s selector and offset. It utilizes index and descriptor table to do the same. you can imagine it like pages and line no. pages cannot overlap each other.

A new concept was introduced with this which is known as virtual memory. The basic idea of virtual memory system is to only keep the data and code in memory which is currently used by the program. And other data is stored on disk. Each segment is assigned an entry in descriptor table, which holds information like, is it currently in memory, access permissions. The only disadvantage of 16-bit protected mode was the 64K limit which still into play as we can only have 16 bit offset.

32-bit Protected Mode

They were introduced in 80386. as now offset can be of 32 bits this allowed segments to have sizes up to 4 gigs. A new concept with this arose “pages” now each segment is composed of 4K pages and virtual memory can now uses pages instead of switching big segments.

Little bit about Interrupts

Interrupts are the mechanism which kicks in when something unexpected occurs or something that require prompt response. Routines that handles an interrupt are called interrupt handlers (of course! :P ). All interrupts are assigned with an integer no. that are defined at the beginning of the physical memory as a table of interrupt vectors.

There is one more category called “Traps”. They are also interrupts but shows fatal error. There is no way to get out of these and the system will crash out.

Generally interrupt handler returns to the interrupted program. They backup all the registers before handling the interrupts and restore them afterwards, Traps being an exception. Traps don’t return to the interrupted programs.

I guess this is all for today.. will add more soon.
till then..

Published inAssembly Language

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *