CS-220, Week 3A Spring, 2006 R. Eckert PREPARING AN 80X86 ASSEMBLY LANGUAGE PROGRAM 1. Enter the source assembly language program using an editor like EDIT --> .ASM file 2. Translate the assembly language to machine language using an assembler program like MASM --> .OBJ file (machine readable) You may want to request a human-readable version of the translation called a list file (.LST file) You may also want to request a cross reference listing to aid in debugging (.CRF file) 3. Link the object file to Operating System (and other) modules using a linker program like LINK --> the executable, .EXE file You may also want to get a memory map showing where the various modules will be placed when the executable is loaded into memory (the .MAP file) You may also want to supply other .OBJ files from a library (.LIB file) The MASM version 6.11 package allows you to combine steps 2 and 3 with the ml program which does both the assembling and linking. 4. Execute the program (.EXE file) by typing in its name at the DOS prompt. For details of how these steps are carried out, see the Lab 1 Handout from the "Lab 1 Assignment" link on the class Web pages. OVERVIEW OF THE 80X86 ARCHITECTURE (REGISTERS, ACCESSING MEMORY) Also see Chapter 2 of your Irvine textbook. The following is a block diagram of internal organization of the Intel 8088 microprocessor. The 8088 is somewhat simpler than the 8086. The main differences are the fact that the latter has a 16 bit internal data and a six-byte-deep instruction prefetch queue. The Internal Organization of the Intel 8088 MicroprocessorThe following diagram shows the Intel 8086 16-bit registers that are accessible to the assembly language programmer. Also see Figure 2-9 in your text book to see the Intel 80X86 32-bit registers.
ACCESSING MEMORY WITH AN INTEL 8086/8088-BASED COMPUTER -- REAL ADDRESS MODE
Memory is accessed by providing a 20-bit "physical address." Physical addresses are generated by the bus interface unit part of the processor. Since the processor's pointer registers (IP, SI, DI, BX, SP, BP) are only 16 bits wide a method of storing a 20-bit physical address must be found. Intel came up with the idea of memory "segments." A segment is a 64K byte block of memory, any byte of which can be accessed with a 16-bit pointer register (2^16 = 64K). In an 8086 or 8088-based computer, there can be up to four active memory segments at any time, and a segment can be located anywhere in the 1 Mbyte memory space (2^20 = 1M). A physical address of any memory location is then given by the following:
Physical address = address of base of segment + offset of location within segment
We say that a segment is "pointed to" by a segment register. In other words a segment register will always hold the information needed to get the base address of the segment it points to. What is actually stored in a segment register is the base address of the segment divided by 16. In other words, segments always begin on "paragraph boundaries" -- addresses divisible by 16 (or that end in a hexadecimal 0). Since this is the case, the least significant hex digit of the base address does not need to be stored. So the segment register will always contain the base address divided by 16 -- a 16-bit number. Any time the processor accesses memory, it computes the physical address by taking the contents of the appropriate segment register, left shifting it by 4 bits (i.e., multiplying it by 16) to get the segment's base address, and then adds the appropriate offset:
Physical address = (contents of segment register)*16 + offset
Depending on the kind of memory access, different segment registers are used to hold the segment base and other registers are used to hold the offset. The following table shows the most common ways of accessing memory in an 80x80-based system:
Type of memory access Segment Register Alternate Seg. Reg. Offset ----------------------------------------------------------------------- Instruction fetch CS none IP Stack access SS none SP or BP Data access DS CS, SS, ES DI, SI, or BX Symbolic data access DS CS, SS, ES generated by assembler
See Section 2.3 of your textbook for a brief description of Real and Protected mode memory addressing for the Intel 80X86 family of microprocessors.