Register (the working principle of cpu)

Source: "Assembly Language " by Mr. Wang Shuang .

1. A typical CPU consists of devices such as arithmetic units, controllers, registers , etc., which are connected by an internal bus.

the difference:

The internal bus realizes the connection between various devices within the CPU.

The external bus realizes the connection between the CPU and other devices on the motherboard.

The 8086CPU has 14 registers and their names are:

   AX 、 BX 、 CX 、 DX 、 SI 、 DI 、 SP 、 BP 、

   IP、CS、SS、DS、ES、PSW。


All registers of the 8086CPU are 16-bit, and can store two bytes, one byte with 8 bits.

AX, BX, CX, DX are usually used to store general data and are called general-purpose registers.

What is the maximum amount of data that can be stored in a 16-bit register? 

Because the data stored in each bit is 0 or 1, then the largest value is naturally 1111 1111 1111 1111 (2), which is 2^16-1.


2. General-purpose registers (emphasis)

The registers in the previous generation CPU of 8086 are all 8 bits. To ensure compatibility,

These four registers can be divided into two independent 8-bit registers for use.
AX can be divided into AH and AL;
BX can be divided into BH and BL;
CX can be divided into CH and CL;
DX can be divided into DH and DL.

The lower 8 bits (0-7 bits) of AX constitute the AL register, and the upper 8 bits (8-15 bits) constitute the AH register.

The AH and AL registers are 8-bit registers that can be used independently. If they are used as 8-bit registers, then they are independent and have nothing to do with each other.

What is the maximum value of data that can be stored in an 8-bit register? The binary value is 1111 1111 , which is 2^8-1.


3. Storage of words in registers





Note: When performing data transfer or operation, pay attention to the number of bits of the operand of the instruction to match.


4. Representation of physical address (emphasis)

When the CPU accesses the memory unit, the address of the memory unit is given, and the storage space formed by all the memory units is a one-dimensional linear space.

We call this unique address the physical address.

Different CPUs have different ways of forming physical addresses.

(1) CPU with 16-bit structure

8086内部为16位结构,它只能传送16位的地址,表现出的寻址能力却只有64K。

8086外部有20位地址总线,可传送20位地址,寻址能力为1M。

那么,8086CPU如何用内部16位的数据,转换成20位的地址呢?

8086CPU采用一种在内部用两个16位地址合成的方法来形成一个20位的物理地址。

段地址+偏移地址 -> 地址加法器 -> 20位的物理地址。

地址加法器合成物理地址的方法:段地址×16+偏移地址=物理地址

“段地址×16”有一个更为常用的说法就是数据左移4位。(二进制位)

二进制的数据左移4位,意味着乘以2^4=16。

这样做的目的主要是为了弥补内部总线16位的缺陷而设计的。






5、关于段空间

内存没有分段,段的划分来自于CPU,

由于8086CPU用“(段地址×16)+偏移地址=物理地址”的方式给出内存单元的物理地址,

使得我们可以用分段的方式来管理内存。

以后,在编程时可以根据需要,将若干地址连续的内存单元看作一个段,

用段地址×16定位段的起始地址(基础地址),用偏移地址定位段中的内存单元。

(1)段地址×16 必然是 16的倍数,所以一个段的起始地址也一定是16的倍数;

(2)偏移地址为16位,16 位地址的寻址能力为 64K,所以一个段的长度最大为64K。

CPU可以用不同的段地址和偏移地址形成同一个物理地址。

如果给定一个段地址,仅通过变化偏移地址来进行寻址,最多可以定位多少内存单元?

因为偏移地址16位,变化范围为0~FFFFH,仅用偏移地址来寻址最多可寻64K个内存单元。

比如:给定段地址1000H,用偏移地址寻址,CPU的寻址范围为:10000H~1FFFFH。

6、地址的描

在8086PC机中,存储单元的地址用两个元素来描述。即段地址和偏移地址。

“数据在21F60H内存单元中。”对于8086PC机的两种描述:

(a)数据存在内存2000:1F60单元中;

(b)数据存在内存的2000段中的1F60H单元中。

可根据需要,将地址连续、起始地址为16的倍数的一组内存单元定义为一个段。


7、段寄存器就是提供段地址的。

8086CPU有4个段寄存器: CS、DS、SS、ES。

CS和IP是8086CPU中最关键的寄存器,它们指示了CPU当前要读取指令的地址。

CS为代码段寄存器,IP为指令指针寄存器。

在 8086CPU 加电启动或复位后( 即 CPU刚开始工作时)CS和IP被设置为CS=FFFFH,IP=0000H。

即在8086PC机刚启动时,CPU从内存FFFF0H单元中读取指令执行。

FFFF0H单元中的指令是8086PC机开机后执行的第一条指令。










8、修改CS,IP

mov指令不能用于设置CS、IP的值,8086CPU没有提供这样的功能。

8086CPU为CS、IP提供了另外的指令来改变它们的值:转移指令

JMP 段地址:偏移地址

JMP 2AE3:3

功能:用指令中给出的段地址修改CS,偏移地址修改IP。CS = 2AE3H, IP = 0003H。

仅修改IP的内容:

jmp 某一合法寄存器

jmp ax   (类似于 mov IP,ax)

功能:用寄存器中的值修改IP。

8086机中,任意时刻,CPU将CS:IP指向的内容当作指令执行。



9、关于debug指令(Win7没有这个指令,XP才有)

R命令查看、改变CPU寄存器的内容;

D命令查看内存中的内容;

E命令改写内存中的内容;

U命令将内存中的机器指令翻译成汇编指令;

T命令执行一条机器指令;

A命令以汇编指令的格式在内存中写入一条机器指令。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325973850&siteId=291194637