About me
Home
Resumé
CV
Pictures

Course Work
CSE300-FA98

Teaching
Portfolio
CSE240-SP99
CSE207-FA03

Misc
eHarmony
Documents

Tools

Effective Addresses

Let me preface this web page with this is messy - sorry. I'm going to try to come back to this page and fix it up once I get a few questions/comments back. I will cover this material better in class. --Barry

Now that you have seen the basics of how to work in Intel 80xxx Assembly, we should probably look at some of the details. Your book covers the different registers and the primary uses for these registers in some detail (p.22-23 ignore i386+ for now) and the flags (p.62-68). What is doesn't cover very well is effective addresses and what the segmentation is for in the Intel architecture.

This is one of those times, I wish I was in front of the board because it will be much easier to explain. However, I will try to do my best, and if you have any questions email me.

A register (DX, BP, etc) is 16-bits wide. With 16 bits, you can represent a number 0000-FFFF in hexidecimal. This represents the possible addresses we can access in memory. I dropped 32 megs of RAM in my computer, can I access all of it if a register only lets me address 64KB (FFFF)? Unfortuantely, this course will not cover how one addresses more than 640KB of RAM. But even still, 640KB (FFFFF), do we address that much space? It looks like it is stuck with only being able to represent 64KB (FFFF).

What Intel did was to add segment registers. Segments are represented by another register (CS, DS, SS, ES) and they are added to another register to compute the effective address. For example, the instruction pointer (IP) register by default uses the code segment (CS) register to compute its effective address. Effective addresses are always computed as segment*16+offset. In hexidecimal, this is easy to do, simply shift the segment value by one position. Let's say our code segment is equal to 1234 and our instruction pointer is at 89AB. To compute the effective address we would write

    89AB
+  1234
---------
   1ACEB

Why do we care about this? Well, one advantage of separate segments is protection of data. If we put our code in segment 0000 and our data in segment 1000 there is no way we can accidently mis-set a pointer register and overwrite a portion of our code. Of course, if we mis-set a pointer and segment register all bets are off. Typically, your programs will set DS when you start, and you will not change this value.

Of course, advantages do not usually come without some added confusion. Please note that it is possible to represent an address in memory using many different combinations of segments and pointers.

    79AB  
+  1334
---------
   1ACEB
    78AB  
+  1344
---------
   1ACEB

In short, don't get too hung up on effective addresses, but understand that this is how they are computed. If you are using the debugger, you will want to locate some of your data or code and will need to type it in as a segment:offset. I will hopefully put up a short tutorial on how to use the Turbo Debugger in the next few days.

If you go back and look over the book, this may make a little more sense now. If not, please bring questions to class so I can review this material and not put you to sleep.

Last Modified: January 26, 1999 - Barry E. Mapen