当前位置:网站首页>Detailed explanation of super complete knowledge points of instruction system
Detailed explanation of super complete knowledge points of instruction system
2022-07-28 10:15:00 【interval_ package】
Command system
One 、 Machine instructions
Instruction system is the language system of computer hardware , Also called machine language , Refers to the set of all instructions that the machine has , It is the main interface between software and hardware , It reflects the basic functions of the computer . From the perspective of system structure , It is the main attribute of the computer seen by the system programmer . Therefore, the instruction system represents the basic functions of the computer and determines the required capabilities of the machine , It also determines the format of instructions and the structure of the machine . Designing instruction system is to choose some basic operations in computer system ( Including operating system and high-level language ) Should it be implemented by hardware or software , Selecting some complex operations is implemented by a special instruction , It is still implemented by a series of basic instructions , Then determine the instruction format of the instruction system 、 type 、 Operations and access methods to operands .
An instruction is a statement in machine language , It's a meaningful set of binary code , The basic format of the instruction is as follows: : Opcode fields + Address code field , The operation code indicates the operation nature and function of the instruction , The address code gives the operand or the address of the operand .
1. General format of instructions
The basic format of the instruction is as follows: : Opcode fields + Address code field , The operation code indicates the operation nature and function of the instruction , The address code gives the operand or the address of the operand .
| Opcode fields | Address code field |
|---|---|
| Indicates the operation nature and function of the instruction | Gives the operand or the address of the operand |
(1) opcode .
- The operation code is used to reflect the operation to be completed by the instruction .
- The number of operation code digits reflects the basic allowable operation quantity of a certain type of machine , That is, the number of instructions .
- The length of the opcode can be fixed or variable .
Extended opcode technology
- Extended opcode is an instruction optimization technique , That is, let the length of the opcode decrease with the number of addresses Less but more ( That is to expand ). According to different address instruction formats , Such as three addresses 、 2. Address 、 Single address instruction, etc , The number of digits of the opcode can be selected in different ways , So that on the premise of meeting the needs , The instruction length is effectively shortened .
- Code making 4 Bits can indicate 16 Orders , Because only 15 strip , So there is still a state left
1111, You can mark two address instructions . - Pay attention to the three addresses here 、 2. Address 、 The single address is different from the address code division below .
(2) Address code
Address code , Used to indicate the source operand address of the instruction 、 Result address 、 The address of the next instruction ( If we agree on the rules, we don't need to record ). The address here can be the address of main memory 、 Register address 、IO Device address .
- The length of an address code field , It reflects the address range it can cover . So we have to find a way to lengthen the length of the address code field .
- If the opcode length is fixed , Fixed command word length , Then if the number of separate address fields is more , Then the shorter the length of a field . We need to reduce the number of fields .
- there N The address instruction is related to the previous , But it's different .
| Instruction type | Instruction content | performance | How to optimize |
|---|---|---|---|
| Four address instructions | There are four address fields , They are No 1、2 Operands , Result storage location , Next command position | Access the memory four times , If we have a program counter PC Words , The next command position is not permanent | Cancel the field of the next position |
| Three address instructions | Basically the same as the four fields | Or access the memory four times , But by PC Control the next command | The result of each operation does not have to be placed in main memory , It can also be placed in the position of the previous operand , perhaps CPU In the register |
| 2. Address instruction | Deleted the result storage location | If it exists in the position of the previous operand ,4 Time . Put the register on 3 Time | Suppose that the result of our previous operation has been placed in the register , We can discard the first operand |
| Single address instruction | We added registers ACC, Last calculation result , Put it in , For the first operation , Is to take data and put it | ||
| Zero address instruction | There is no opcode in the instruction word | Used for some instructions without operands or implied operands |
2. Instruction word length
- Machine word length : The number of bits of binary data that a computer can process in an integer operation .
- Instruction word length : The total number of bits of binary code in machine instructions , The instruction word length depends on the length of the slave opcode 、 The length of the operand address and the number of operand addresses . The word length of different instructions is different .
- Storage word length : A storage unit stores a string of binary code , The number of bits in this string of binary code is called the storage word length , The storage word length can be 8 position 、16 position 、32 I'm waiting for you .
Two 、 Operand type and operation type
1. Operand type
Address 、 Numbers 、 character 、 Logical data, etc .
2. How data is stored
(1) Boundary alignment
If we have a data , When it is stored, it crosses two machine words , Then you need to access and store data many times , The allocation of addresses is also unclear .
Data aligned storage actually means that the data address is stored according to an integer multiple of the size of its data type , The purpose is to make the data read continuously with the least number of times .
If 32 When the bit system reads data, one word is 32 Bits or 4 Bytes , When data is stored , Try to allocate addresses according to an integer multiple of the size of the data type .
- For example, in the data : - - int by 4 Bytes ; - long long yes 8 Bytes ; - char by 1 Bytes . - Then in memory address allocation : - - int It can only be placed at the first address 0,4,8 Location ; - long long The first address is 0,8,16 Location ; - char It can be placed anywhere .
When the computer is reading , about int Type data only needs one cycle ,long long Two cycles . But if stored in natural order ,int Type may require two cycles , At this time int Type data spans the storage space of two words , Equivalent to a warehouse with several rooms ( word ), Every room has 4 Numbered sequentially ( Address ) Box of ( byte ), Every time you enter a room is equivalent to a cycle .
When the stored data is less than one word long , Blank bytes can be added to fill .
(2) Byte order
Byte order , As the name implies, the order of bytes , Two more sentences are the storage order of data larger than one byte type in memory ( A byte of data, of course, does not need to talk about the order of the problem ).
In fact, most people seldom deal directly with byte order in actual development . Only in cross platform and network programs, byte order is a problem that should be considered . In all articles introducing byte order, it will be mentioned that byte order is divided into two categories :Big-Endian and Little-Endian. Quoting standard Big-Endian and Little-Endian Is defined as follows :
- a) Little-Endian That is, the low byte is discharged at the low address end of the memory , The high byte is placed at the high address end of the memory .
- b) Big-Endian That is, the high byte is discharged at the low address side of the memory , The low byte is placed at the high address of the memory .
- c) Network byte order
For low byte low address and high byte low address , In the vernacular, it is , We have this number from left to right , Or read from right to left .
num_real = 123456
Little-Endian = 1 2 3 4 5 6
Big-Endian = 6 5 4 3 2 1 Instead, the high-order numbers are the low-order numbers in our real data
3. Operation type
| Operation type | eg |
|---|---|
| Data transfer | MOV, LOAD, STORE |
| Arithmetic Logic | Add, subtract, multiply and divide |
| displacement | Arithmetic shift , Logical shift , Cyclic shift |
| IO |
Transfer
| type | |
|---|---|
| To transfer unconditionally | |
| Conditional transfer | SKP, BRO |
| Call and return | CALL, RETURN |
| Traps and trap instructions | Traps are unexpected interruptions , Trap instructions are generally implicit instructions ,CPU Automatic execution |
3、 ... and 、 Addressing mode
The purpose of addressing , One is to find the data you need now , One is to find the location of the next instruction .
1. Command addressing
Basically sequential addressing and skip addressing . Sequential addressing depends on PC Self increasing , Jump addressing is the basic jump
2. Data addressing
There are many ways to address data , You need to set a field in the instruction word to specify the type . And the address code field is not necessarily the real address , It is generally called formal address , Remember to do A.
For real addresses , Write it down as EA.
(1) Address immediately
The direct instruction itself carries data , in other words , Formal address A The content in is no longer an address , Instead, it is directly the operand .
The operand is in the instruction , Immediately following the opcode , Stored as part of the instructions in the code segment of memory , The operand is immediate , This addressing method is called immediate addressing . Data is usually stored in the form of complement . It is often used to assign initial values to registers ( effect )
① The immediate number can be sent to the register 、 One storage unit (8 position )、 Two consecutive storage units (16 position ) In the middle ;
② An immediate can only be used as a source operand , Cannot be used as destination operand ;
③ With A~F The leading numbers , Numbers must be added in front 0.
advantage : The instruction has provided operands , No need to access the memory again . Provide operands The fastest .
shortcoming
① The operand is part of the instruction , Do not modify , It is applicable to operations such as assigning initial values to a register or storage unit .
② In the instruction A Limit of digits Of the immediate number expressed by such instructions Range .
(2) Direct addressing
A Address for storing data directly in .
(3) Implicit addressing
Do not explicitly give the operand address , Instead, it indicates in a register .
(4) Indirect addressing
There will be a transition in the middle ,A The address is stored in , This address points to the address of the target in the field memory .
(5) Register addressing ( indirect )
The number of the register is given , Not the address of the address unit , Registers can store data , You can also save the address ( indirect ).
(6) Base and indexed addressing
From the definition of both , It doesn't make much difference . It's just Is the reference address or offset address stored in the register . Why not regard it as one ? Let's explain in detail .
Base addressing
- Definition : The instruction gives a register number and a formal address , The contents of the register are the reference address , The formal address is used as an offset .
The reference address plus the offset is the valid address of the operand . - The contents of the base register in base addressing are usually determined by the operating system or the hypervisor , The median value during program execution is immutable . Its offset is variable . Mainly system oriented .
A typical application of base addressing is program relocation . The target program is called into memory by the operating system , The user doesn't know where the memory is . The address used in user programming is actually a logical address , It will be converted to the actual physical address at run time in the future . In the base address addressing mode , When the program relocates, the operating system assigns a reference address to the user ( In the reference register ), When the program is executed, it can be mapped to a physical address . - And reference addressing can expand the addressing range ( The number of bits of the base address register is greater than the number of bits of the formal address ). for instance : Main memory 16M, Base register 24 position ( Not a register address 24 position !). The address segment in the instruction uses 16 position ,2 Bits are used to address registers ( Suppose by 4 A register , You need two addresses ), The remaining 14 Bit gives displacement , Accessible 16KB Continuous storage space . Every time you modify the value of the base register , Then base address plus index can find continuity every time 16KB Space . Significantly improve addressing performance
Addressing
- Definition : Instruction gives a register number and formal address , The contents of the register are used as offsets , The formal address is used as the reference address . Base address plus offset to get effective address .
- Indexed addressing is user oriented , The contents of the index register can be changed by the user , Form address unchanged ( Written directly in the instruction ). Commonly used in arrays . You can set the first address of the format address bit group , Each time by changing the value of the index register to achieve the operation of the array .
- That is, it can be modified by indexing , Make the same piece of code can access different content
(7) Relative addressing
PC+A
(8) Stack addressing
Stack addressing : Operands are stored on the stack , Implicitly use stack pointers (SP) As an operand address .
The stack is a register ( Or special register group ) Press... For a specific piece of " Last in, first out (LIFO)"
Principle managed storage , Read in this store / The address of the write unit is given in a specific register , This register is called a stack pointer (SP)
边栏推荐
- 建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
- vc链接静态库的时候要注意的问题
- Redis interview questions must be known and learned
- Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
- MySQL架构原理
- leetcode076——数组中的第 k 大的数字
- Digital construction of pharmaceutical industry is on the verge
- Netease written test No. 2 -- typical application of European distance
- 吴雄昂遭Arm罢免内幕:建私人投资公司,损害了股东利益?
- Skillfully use NGX_ Lua makes traffic grouping
猜你喜欢

初识SuperMap iDesktop

选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步

Skillfully use NGX_ Lua makes traffic grouping

Flink - checkpoint Failure reason: Not all required tasks are currently running

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control

On July 13, 2021, we collapsed like this

软件设计师考前20问,注意啦!!
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

工业品MRO采购网站有哪些优势?一文带你读懂
![[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
随机推荐
Leetcode -- minimum number of rotation array
Description of landingsite electronic label quppa firmware entering DFU status
Joint search set
软件设计师考前20问,注意啦!!
centos7下安装mysql,网上文章都不太准
5、动态规划---斐波那契数列
19. 删除链表的倒数第 N 个结点
什么样的知识付费系统功能,更有利于平台与讲师发展?
Double pointer technique
Sort - quick sort (fast and slow pointer Implementation)
Redis interview questions must be known and learned
Digital construction of pharmaceutical industry is on the verge
13 probability distributions that must be understood in deep learning
工业品MRO采购网站有哪些优势?一文带你读懂
Uni app advanced life cycle
Leetcode076 -- the kth largest number in the array
[cloud co creation] enterprise digital transformation, Huawei cloud consulting is with you
6、双指针——递增数组两数之和与目标数相等
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效