当前位置:网站首页>Wang Shuang's detailed notes on assembly language learning I: basic knowledge

Wang Shuang's detailed notes on assembly language learning I: basic knowledge

2022-07-06 14:41:00 Deteriorate_ Kr


Preface

Assembly language is a programming language that works directly on hardware , First, understand the structure of the hardware system , In order to effectively apply assembly language to its programming .


One 、 From machine language to assembly language

1. machine language

Machine language is a collection of machine instructions .

In terms of machine instruction deployment, it is the command that a machine can execute correctly .

The machine instruction of an electronic computer is a list of binary numbers , Computers can only read binary numbers .

Obviously , If you use machine instructions to program, it is so difficult to distinguish and remember , A little carelessness will lead to mistakes .

2. assembly language

The main body of assembly language is assembly instruction .

The difference between assembly instructions and machine instructions lies in the representation of instructions . Assembly instruction is a writing format that is easy to memorize .

Assembly instructions are mnemonics for machine instructions ( Closer to human language )

But assembly language also needs to be compiled into machine language , Only computers can understand
 Insert picture description here
Assembly language consists of the following 3 Class composition :
1、 Assembly instruction ( Mnemonics for machine codes , There is a corresponding machine code )
2、 Pseudo instruction ( By compiler , No corresponding machine code , Computer does not execute )
3、 Other symbols ( Recognized by compiler , No corresponding machine code , Such as + - * / etc. )

The core of assembly language is assembly instruction , It determines the characteristics of assembly language .





Two 、 Memory

1. Instructions and data

CPU It's the core component of a computer . It controls the operation of the whole computer and performs calculations , If you want a CPU Work , You have to give it instructions and data .
Instructions and data are stored in memory , That's what we usually call memory . At one PC The role of memory in the machine is second only to CPU.
Instructions and data are applied concepts .
On memory or disk , There is no difference between instructions and data , It's all binary information .
for example , Binary information in memory 1000100111011000, Computers can think of it as having a size of 89D8H Data to process , It can also be regarded as an instruction mov ax,bx To deal with it

Out of memory , The best performance CPU Can't work .
Disk is different from memory , If the data or program on disk is not read into memory , You can't be CPU Use .

2. Storage unit

 Insert picture description here
The minimum information unit of a computer is bit( The bit ), It's a binary bit .
The basic unit of a computer is bytes (byte),1byte=8bit
A storage unit can store one Byte, That is, eight binary bits

For large capacity memory, the following units are generally used to measure capacity ( The following is used B To represent the Byte):
1KB=1024B
1MB=1024KB
1GB=1024MB
1TB=1024GB
The unit of capacity of a disk is the same as that of memory , In fact, the above units are commonly used in microcomputers





3、 ... and .CPU Read and write to memory

CPU To read and write data , It has to be with external devices ( The standard way of saying is chip ) Interact with three types of information :
Address of the storage unit ( Address information )
Device selection , Read or write command ( Control information )
Read or write data ( Data and information )

In the computer, there are special connections CPU And the wires of other chips ( A computer can handle 、 The transmitted signals are all electrical signals , Of course, electrical signals should be transmitted by wires ), Commonly referred to as a bus .
Physically speaking, a bus is a collection of wires ;
Logically divided into :
Address bus
data bus
Control bus

 Insert picture description here

1. How to command the computer to read and write data ? That is, how to make CPU What about work? ?

Passing instructions
Of course, it includes machine instructions and assembly instructions



2. Address bus

CPU It is through the address bus to specify the storage unit .

How many different messages can be transmitted on the address bus ,CPU How many memory units can be addressed .(10 Root address bus ,CPU You can visit 1024 Storage unit , A storage unit stores bytes )

1. There are several address buses ,CPU You can transfer several binary numbers , this 10 A binary number can represent 2^10 The power is different data , The size range is 0→1023. The minimum number is 0, The maximum number is 1023

2. One CPU Yes N Root address bus , It can be said that CPU The address bus width of is N.
In this way CPU At most, you can look for 2 Of N Next memory unit .




3. data bus

The width of the data bus determines CPU And external data transmission speed . Each data bus transmits one binary number at a time ,8 The root data bus can transmit one at a time 8 Bit binary data ( A byte ),16 The root data bus can transfer two bytes at a time .





4. Control bus

How many control buses are there , Means CPU How many controls are provided for external devices .
therefore , The width of the control bus determines CPU The ability to control external devices .
The memory read or write commands mentioned above are issued by several control lines :
One of them is called read signal output control line, which is responsible for CPU Send the read signal out ,CPU Outputting a low level to the control line indicates that data is to be read ;
There is a control line called write signal output, which is responsible for CPU Send a write signal to the outside .


Four . Summary

(1) Assembly instructions are mnemonics for machine instructions , One to one correspondence with machine instructions .
(2) Each of these CPU Each has its own assembly instruction set .
(3)CPU Information that can be used directly is stored in memory .
(4) There is no difference between instruction and data in memory , It's all binary information .
(5) Storage units are numbered sequentially from zero .
(6) A storage unit can store 8 individual bit ( Written as a unit “b”), namely 8 Bit binary number .
(7)1B = 8b 1KB = 1024B
1MB = 1024KB 1GB = 1024MB
(8) every last CPU Chips have lots of pins , These pins are connected to the bus . It can also be said that , These pins lead to the bus . One CPU The width of three kinds of buses marks this CPU Different aspects of performance :
The width of the address bus determines CPU The ability to address ;
The width of the data bus determines CPU The amount of data transferred at a time when data is transmitted with other devices ;
The width of the control bus determines CPU The ability to control other devices in the system .
(9) Insert picture description here





5、 ... and . Memory address space

What is a memory address space ?
One CPU The width of the address line is 10, So you can address 1024 Memory units , this 1024 The memory units that can be found constitute this CPU Memory address space of

1. a main board

At every station PC In flight , There's a motherboard , There are core devices and some major devices on the motherboard .

These devices go through the bus ( Address bus 、 data bus 、 Control bus ) Connected to a .

These devices have CPU、 Memory 、 Peripheral chipsets 、 Expansion slot, etc . The expansion slot is usually inserted with RAM Memory modules and various interface cards

2. Interface card

CPU Cannot directly control external equipment , Like a display 、 Loudspeaker box 、 Printers, etc . Directly controlling these devices is the interface card inserted in the expansion slot .CPU You can directly control these interface cards , So as to achieve CPU Indirect control of peripherals . In short, it is CPU Send commands to the interface card through the bus , Interface card according to CPU Command to control the peripheral to work .

3. Various memory chips

a PC In flight , With multiple memory chips , These memory chips are physically independent 、 Different devices .
From the reading and writing properties, it can be divided into two categories :
Ram (RAM, Can read but write , But it has to be stored live , The stored content is lost after shutdown ) And read only memory (ROM, read-only , The content will not be lost after shutdown )

Classify from function and connection :
1. Ram RAM
Used to store for CPU Most of the programs and data used , The main random access memory (RAM) generally consists of RAM form , Installed on the motherboard RAM And plug in the expansion slot RAM

2. Equipped with BIOS Of ROM
BIOS:Basic Input/Output System, Basic I / O system .
BIOS It is made up of motherboard and various interface cards ( Such as : The graphics card 、 Network card, etc ) Software system provided by the manufacturer , It can be used to make the most basic input and output of the hardware device . In the motherboard and some interface cards, there is a corresponding storage BIOS Of ROM.

3. On the interface card RAM
Some interface cards require a large number of inputs 、 Output data for temporary storage , It is equipped with RAM.
The most typical one is on the display card RAM, It's called video memory . The display card will output the data in the video memory to the display at any time . let me put it another way , We write what we need to display into video memory , It will appear on the monitor .

 Insert picture description here

4. Logical memory

The above memories are physically independent devices .
But they are the same in two ways :
1、 And all CPU Bus connection of .
2、CPU When reading or writing to them, the command of memory reading and writing is issued through the control line .

in other words ,CPU When manipulating these physically independent memories , Treat them as memory , They are generally regarded as a logical memory composed of several storage units , This logical memory is what we call memory address space .

1. All physical memory is regarded as a logical memory composed of several storage units ;
2. Each physical memory occupies an address segment in this logical memory , It's an address space ;
3.CPU Read and write data in this address space , In fact, it is to read and write data in the corresponding physical memory

 Insert picture description here
The allocation of memory address space is different in different computer systems .
When we are programming based on a computer hardware system , You must know the allocation of memory address space in this system . Only in this way can the corresponding memory be read and written correctly .
 Insert picture description here

5. Summarize memory address space :

The final thing to run the program is CPU, When we use assembly programming , It must be from CPU Point of view .
Yes CPU Speaking of , All memory units in the system are in a unified logical memory , Its capacity is limited by CPU Limitation of addressing capability . This logical memory is what we call the memory address space .

原网站

版权声明
本文为[Deteriorate_ Kr]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060919069527.html