Frage

I took Computer Architecture course and I understood that processor has 32 registers each of 32 bit. Now I am studying computer architecture course in which I read that 8086 has 8 registers only. But the book I read and this website shows many registers. I am getting confused about the registers in 8086 and 8088. Please help me out.

NOTE:

I have a good understanding of different register sizes in different processors. I am just getting confused in the number of registers.

War es hilfreich?

Lösung

The 8086 and 8088 are 16 bit processors - their registers are each 16 bits in width. (A few instructions treat the combination of DX and AX as a 32 bit integer, like div input and mul output.)

Note that the 8086 has 16 bit data bus; the 8088 has an 8 bit data bus. (So loading/storing a 16-bit word takes 2 bus cycles. Addresses are still 20-bit for both.)

GENERAL PURPOSE REGISTERS

8086 CPU has 8 general purpose registers, each register has its own name:

AX - the accumulator register (divided into AH / AL):

Generates shortest machine code: short-form encodings exist
Arithmetic, logic and data transfer
One number must be in AL or AX
Multiplication & Division
Input & Output

BX - the base address register (divided into BH / BL).

Offset address relative to DS by default

CX - the count register (divided into CH / CL):

The LOOP instruction uses it implicitly as a counter
Repetitive operations on strings with the REP command
Count (in CL) of bits to shift and rotate

DX - the data register (divided into DH / DL):

DX:AX concatenated into 32-bit register for some MUL and DIV operations
Specifying ports in some IN and OUT operations

SI - source index register:

Can be used for pointer addressing of data
Used as source in some string processing instructions
Offset address relative to DS by default

DI - destination index register:

Can be used for pointer addressing of data
Used as destination in some string processing instructions as ES:DI
Offset address relative to DS outside of string instructions

BP - base pointer:

Primarily used to access parameters and locals on the stack
Offset address relative to SS

SP - stack pointer:

Always points to top item on the stack
Offset address relative to SS (but can't be used in 16-bit addressing modes)
Should always points to word (byte at even address)
An empty stack will have SP = FFFEh

SEGMENT REGISTERS

  • CS - points at the segment containing the current program.
  • DS - generally points at segment where variables are defined.
  • ES - extra segment register, it's up to a coder to define its usage.
  • SS - points at the segment containing the stack.

Although it is possible to store any data in the segment registers, this is never a good idea. The segment registers have a very special purpose - pointing at accessible blocks of memory.

Segment registers work together with general purpose register to access any memory value. For example if we would like to access memory at the physical address 12345h (hexadecimal), we could set the DS = 1230h and SI = 0045h. This way we can form 20-bit linear addresses, instead of just 16 bit with a single register. (This applies in real mode; in protected mode segmentation is different.)

The CPU makes a calculation of the physical address by multiplying the segment register by 10h and adding the general purpose register to it (1230h * 10h + 45h = 12345h):

The address formed with 2 registers is called an effective address.
By default BX, SI and DI registers work with DS segment register;
BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address.
Also, although BX can form an effective address, BH and BL cannot.

SPECIAL PURPOSE REGISTERS

IP - the instruction pointer:

Always points to next instruction to be executed
Offset address relative to CS

IP register always works together with CS segment register and it points to currently executing instruction.

FLAGS REGISTER

Flags Register - determines the current state of the processor. They are modified automatically by CPU after mathematical operations, this allows to determine the type of the result, and to determine conditions to transfer control to other parts of the program. Generally you cannot access these registers directly.

Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in (the low 8 bits of a) result, and to 0 when there is odd number of one bits. 
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow (carry-out) for low nibble (4 bits).
Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the value of the most significant bit.)
Trap Flag (TF) - Used for on-chip debugging.
Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.
Direction Flag (DF) - this flag is used by some instructions to process arrays.  When this flag is set to 0 the processing is done forward, when this flag is set to 1 the processing is done backward.
Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127). 

Andere Tipps

I took Computer Architecture course and I understood that processor has 32 registers each of 32 bit.

This doesn't answer your question, but if you want to communicate with annother engineer, you have to use the proper language. Saying "a (some) processor has 32 registers that are 32 bits in size" won't get you anywhere, there are countless numbers of processors.

The 8086 had eight (more or less general) 16-bit registers including the stack pointer, but excluding the instruction pointer, flag register and segment registers. Four of them, AX, BX, CX, DX, could also be accessed as twice as many 8-bit registers (see figure) while the other four, BP, SI, DI, SP, were 16-bit only.

I'm assuming the confusion comes from this sentence on the Wikipedia. Both of the sources you read are right. There are 8 general purpouse registers (in the article it's noted as "more or less general", i've no idea who could write that), they are: AX BX CX DX and SI DI BP SP. There are also segment registers, special purpouse registers and a flag register (which are noted after the "excluding" word, which, i'm guessing, is suppoused to be read as "there are registers, there's 8 of them if you exclude these 3 groups", it's vague).

The issue is in the wording. The quoted sentence is confusing and i can see where your question is comming from. It never hurts to ask, but you should understand that Wikipedia is not a reliable source of knowledge, if you're ever confused, just pick up a book.

The 8086 has 14 16 bits registers. AX, BX, CX, DX, SI, DI, BP, SP, CS, DS, SS, ES, IP and the flags register. The last two are only accessed indirectly.

Computer architecture books often use MIPS as example because it's rather simple and educational. MIPS has 32 registers but this does not mean that other 32-bit architectures also have 32 registers. 32-bit here only means that the computer has 32-bit address/32-bit integer registers. It's not related to the number of registers in any way.

ARM, the most popular 32-bit architecture, has 16 registers (although ARMv8 64-bit doubled this number to 32). Many other 32-bit architectures also have register number other than 32 such as Motoroka 68k and SuperH v2/3/4, all have 16 registers. For the list of architectures look at here. You see, 64-bit architectures rarely have 64 registers, as that'll increase the register file size a lot, and makes context switch worse. Most of them have 32 registers.

x86, being backward compatible with 8086 many decades ago, has only 8 visible integer registers. But in fact x86 CPUs nowadays have hundreds of registers inside and use register renaming to overcome the limit in number of registers.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top