Architecture of 8086 processor

Assembly language is usually said to be the lowest level language. The highest language is a natural language used by people. Human is at the highest and machine is at the lowest. The lower is the closer to the machine. Assembly language is the closest machine in every programming language. So to do something in assembly language you need to know the machine first. That's why we describe numbers and machines before assembly language itself. In this article, we will look at what features 8086 has and what features we can manipulate with assembly language. Is there anything closer to the machine than the assembly language? There is a number. Every assembly language is converted to a machine-understandable number that makes the machine work directly. Assembler does converting an assembly into number and the task itself is called assembling. A collection of numbers is also known as a machine language. It is not the language of a person. So the minimal language that humans can use is assembly language. (Yes, long time ago some genius people remembered numbers and write numbers instead of assembly code. But number is number, not language.) Note that the assembly language is matched one to one with numbers. For example, mov command will always be converted to a specific number. Assuming this value is 12h, the assembler will convert it to 12h when it encounters mov in your code. Let's say that we have the command "mov ax bx", assembler always convert it to 1234h. Assembler is a very simple program compared to compiler.

This picture is a very, very simple representation of a computer. Every component of computer, Memory, processors, and devices are connected by system-bus. Let's assume a file is stored in the hard disk. If we double-click mouse button on the file, the mouse sends signal to processor via the bus. Then processor read a program in memory via the bus and run. Finally the a portion of file is stored in memory. The program also uses the bus to shows the contents of the memory on the monitor.

Processor

If we have executable files that that is generated by the assembler, this file will be stored on the hard disk device. The processor will then move the executable into memory and read and execute the instructions in memory. Considering the architecture of the 8086 processor is simple.

General Registers

Register is a 16-bit storage inside the processor. It has the same role as memory. However, memory and processors are connected by a wire (system-bus)(note 3) and the memory device is slower than the processor, so the processor must wait a while to read the data in memory. However, because the registers are inside the processor, they can be read very quickly. The speed difference is at least 10,000 times. Accessing memory is like the transferation a delivery between cities while accessing register is like taking things out of your pocket. A car which transfers things between cities can carry big carrages but takes a long time. You can take out your pocket items quickly, but there is a drawback that you can not put big things in it.

So, when processor does something, it reads as much data as possible from the memory into the registers and performs calculation with only the register as much as possible. You can think of the space in which temporary data to be used in the middle of calculation to be stored as a register.

8086 processor has 8 general registers.

  • AX: called as accumulation register or called as arithmetic register. It is mainly used for calculations.
  • BX: This is called as base address register. It is mainly used when calculating memory addresses.
  • CX: This is called as counter register. It is mainly used to remember how many times you are repeating in the loop.
  • DX: Data register. The result of the calculation is stored or the data read from memory is saved.
  • SI: This is called as source index register. Used to store the address of the original data in memory copying.
  • DI: This is called the destination index register. It is used to store the address of destination in memory copy etc.
  • BP: Base Pointer Register. Used to preserve stack addresses when calling function.
  • SP: Stack Pointer Register. The current stack address is saved.

I've briefly explained the role of each register, but now you probably do not understand at all. Practice each register directly with emu8086 so you know which register is where and how to use it. Now you only need to know that there are eight registers of these names. And I've told you that each register has its uses, but it's just for common use and you can actually use it at your own purpose. You can use CX for the calculation or store the loop counter in BX. All registers are 16 bits. Especially, AX, BX, CX, DX can be divided into high 8-bit and low 8-bit. The names of high 8-bit are AH, BH, CH, DH. And low 8-bit are AL, BL, CL, DL. When doing some calculations, this calculation can only use 8 bits if it is a calculation that does not require 16 bits. We will practice this with emu8086. What happens if I write a value of 1234h in the AX register? Will 12h be stored in AH and 34h stored in AL? Or will 12h be stored in AL and 34h stored in AH? We will check in next chapter. In this chapter it's enough if you understand that there are 16 bit registers and they can be used in each 8 bits. Even the acient 8086 computer had 64K~256K memory (https://en.wikipedia.org/wiki/Xerox_NoteTaker) but the register is only 16bit. Why is the register so small? It would be nice to make it big and many because it is very fast. The reason is money. Putting something on the processor takes a lot of money. When you buy the computer for yourself, the processor with the larger cache memory is more expensive because the cache memory is in the processor. The larger the register, the more expensive the processor.

Segment register

8086 has several registers called as segment registers. Similarly, it's enough to just understand that there are such things, and you will learn what role it plays in the next chapters. I will only introduce briefly here.

  • CS: The address of the segment where the current program is saved is saved.
  • DS: The address of the segment where the current data is stored is saved.
  • ES: It has no purpose and stores the segment address of the desired memory location whenever necessary.
  • SS: The address of the segment with the stack is saved.

Segmentation is a concept to make computer support more memory. In the 8086, all registers are 16 bits. Therefore, the register that stores the memory address is also 16 bits. 16 bits are 2 ^ 16, so 2 ^ 10 2 ^ 6 = K 64 = 64K. My laptop has 4G memory. Since the register of the processor of my laptop is 64 bits my laptop can have 4G or bigger memory. Because 8086 has only 16 bits register, 64K is the maximum value that a register can have. But 64K is too small. In the ancient days, bigger memory was also better. So Intel created a way to expand the memory size by use two registers. It would be 32-bit if you put two 16-bit register together, but at that time technology could not make it that big. They only could increase just one nibble. That's it. For example, store 1230h in the DS register and 45h in the SI register. Then the actual address of the memory to be accessed is 1230h * 10h + 45h = 12300h + 45h = 12345h.

That is, a 16-bit register can display only 16-bit, 4-digit addresses like 1234h, but it can be used to display a 5-digit 20-bit address by using a segment register. Then you will be able to connect 1M of memory to the processor because 20-bit can cover 2 ^ 20 = 1M. Do you understand the role of the segment register? Think of it as broadening the address range. Again, for example, to represent an address of 12345h with the 8086 registers, store 1230h in the segment register and store 45h in the SI register. If 1234h is stored in the segment register and 5h is stored in the SI register, it will be the same address. It is the programmer's choice how to use the registers. Only the sum of the two registers should be the desired value.

I've briefly explained the role of segment registers and SI / DI registers, but you might not understand them yet. Let's try some test with emu8086 in next chapters. You will understand them then. Now, It's enough if you understand the memory address is 20 bits and one register is 16 bits, and it is necessary to express two addresses in order to express the memory address. Just notice that the registers used in this case are the segment registers CS, DS, and ES, and the index registers SI and DI.

Special purpose register

There are registers that are not described yet. They are special registers that can not be written and read directly.

  • IP: Instruction Pointer register. Indicates the address of the next instruction to be executed.
  • Flag register: indicates the status of the processor.

These two registers can not be changed by the programmer. The processor automatically changes the value when the program is executed. So both are registers that tell you the state of the processor.

I'll describe the role of each register in practice with emu8086.

This article introduces the many registers. For now just notice that there are several registers in the 8086, each register is 16 bits, and it uses 20 bits with two registers to represent the memory address. We will make assembly code to use each register. Then you will be familiar with each one while writing code. That's why we will use emu8086 tool.


Note1: This picture only show the logical and functional component, not physical.

Note2: The 8086 is called as the first modern processor because everything in the 8086, such as the general registers AX, BX, CX, DX in this figure, and control registers such as CS and IP, are still present in the same processor, for instance, i5 in my laptop. Since 8086, core functions remain unchanged and remain compatible, so we are learning 8086.

Note3: There is a mainboard inside of the computer. If you watch the surface of the mainboard, you can see many green lines. They are very thin wires. Signals from all chips are transferred by the wires.

results matching ""

    No results matching ""