Registers and Memory Addressing
General Registers
Index Registers
Segment Registers
Instruction Pointer
Flag Register
Memory Adressing
8086 is a 16-bit processor. This reflects the maxium size of the values it can work with.
We know that 8 bits is known as a byte. Counting with a byte, those 8 bits can only count to 255.
Just as with 3 decimal places, we can only count up to 999. With 16 bits, known as a Word, we can
count to the number 65,535.
These 8 and 16 bit memory sizes are what shape and limit our operations with the 8086.
The general registers are the Cpu's data banks where all data manipulation takes place.
Certain OpCodes instruct the CPU to move data into a register, or out of one. Also, data can be moved out-to a Ram location
(using a memory address), or in-from a Ram location. Data can be moved between device I/O ports in a simular manner.
The Keyboard Controller has a well known I/O address from which we can fetch a scan code.
I/O PORT is the proper name when speaking a a Chip/Device's I/O Address.
See http:\\pcrepairclass.tripod.com\ for a wealth of info on pc hardware and computer structures.
We can preform simple Math between the contents of a Register and another Register.
We can also preform the same math between a Register and a Memory Location.
But, we can not preform ANY operations between two Memory Locations.
At least one Operand (source or target data required/invloved in a CPU operation) must reside in a register.
.GENERAL REGISTERS
There are four general registers on the 8086. They are 16-bits wide. They can be accessed as a WORD (16-bit) or as a byte.
Every 16-bit register has a HIGH-byte and LOW-byte which can be accessed separately.
16-bit General registers are the AX, BX, CX, and DX. AX encompasses the AH and AL, the high and low bytes of the word sized AX.
Accumluator, Base, Counter, Data
.INDEX REGISTERS
There are Index Registers which can only be accessed as a WORD.
They are used for pointing to memory locations. The Index Registers hold the OFFSET portion of the SEGMENT:OFFSET
memory address. Index Registers are the SI, DI, BP, SP.
Source Index, Destination Index, Base Pointer, Stack Pointer
.SEGMENT REGISTERS
Segment Registers can only be accessed as a WORD.
Values cannot be moved amongst segment registers.
Values can only be moved into them thru memory access or a general register.
If you want to move a value from DS into ES, you'd have to first move the value in DS into a general registar (like AX), and then move that value into ES.
mov ax, ds
mov es, ax
Segment registers contain the SEGMENT in the SEGMENT:OFFSET memory address.
They are the CS, SS, DS, ES.
Code Segment, Stack Segment, Data Segment, Extra Segment
.INSTRUCTION POINTER
The IP register is a 16-bit register which points to the next instruction the CPU must FETCH.
The IP is the OFFSET portion of the SEGMENT:OFFSET address. CPU uses the CS:IP (Code Segment:IP).
.FLAG REGISTER
The Flag register is a WORD sized BIT FIELD. The flags change every time certain Instructions are executed. Wheather a flag is set or cleared depends on the outcome of the operation.
These flags record facts about the previous CPU operation which can be used in a following instuction.
The COMPARE (CMP) instruction takes two operands. It compares the two values by substracting the source operand from the destination operand, HOWEVER, THE values of the operands are NOT changed.
Only the FLAGS are changed, and they have recorded the outcome of the aritmatic. Now, we can use a Control-Transfer instruction, a
Conditional Jump, such as JUMP IF GREATER (JG) to alter the location of executing code. This adds or substracts from the IP.
Overflow, Direction, Interupt, Trap, Sign, Zero, Auxilary Carry, Parity, Carry
.Memory Addressing
Understand the concept of Variables; We can assign a value to a variable. Our program can change it's value. But very important is that the variable will always be there! We depend on it because we will need a safe place to hold values during program execution; the CPU's registers will be no safe place to keep a Remainder from a Division done 30 instructions ago!
Now, all a variable is, is a value held in RAM Memory at a certain Memory ADDRESS. If we know that address, we can access it. We use Segment and Offset addresses to access data when in Real Mode (each address is 16-bits). In REAL MODE our full range of addresses can be accessed with a 20-bit binary number(BIT = Binary digIT).
However, we are limited to 16-bit values (because of the 8086's 16-bit registers).
So How do we count to 2^20 when our Registers only count up to 2^16?
The CPU takes care of this by adding together TWO 16-bit numbers, hence SEGMENT:OFFSET addressing. The addition is done internally. BUT, one of the numbers, the SEGMENT Address, is shifted to a higher place value before it is added. This is the key to achieving 20-bit addressing. Otherwise, only a 17-bit number could be yeilded.
Exp: 23 shifted THREE places to the left becomes 23000
(Above, the example was in decimal. In the CPU we deal with binary.)
The segment address is shifted left FOUR binary digits(places, or bits), this effectivy multiplies the segment address by 16.
Look again to the above example, 23 -> 23000 represents multiplication by 1000. Each Decimal place has a value of TEN, so moving 3 decimal places is a change in value of 10^3 (=1000).
In Binary, each Binary place has a value of TWO. Moving 4 Binary places is a change in value of 2^4 (=16).
The link below is to a GREAT explanation of SEGMENT:OFFSET addressing. You gotta go there.
< http://www.geocities.com/thestarman3/asm/debug/Segments.html >
Segment address + Offset address
6080
+ B423
-----------
becomes
60800
+ B423
-----------
6BC23
-OR- in binary
0110000010000000
+ 1011010000100011
---------------------------
becomes
01100000100000000000
+ 1011010000100011
-------------------------------
01101011110000100011
Don't give up if you get confused or are overwhelmed. Just take a break and start again, or skip to the next section and come back to the biary math when you need to.
__________
Read/Browse VARIOUS literture; you'll pick up small things, after a while you can become intimate with any subject.