Chapter fourth Processor Architecture section Y86 instruction set architecture One, programmer visible State 1. Meaning:
Each instruction will read or modify portions of the processor state
2. "Programmer":
It can be the person who writes the program with the assembler code, or the compiler that produces the machine-level code.
3. Specific processor status: similar to IA32
- There are 8 program registers ,%EAX,%ECX,%EDX,%EBX,%ESI,%EDI,%ESP,%EBP
- Each program register of the processor stores one word
- The register%ESP is used as a stack pointer by a stack, a stack, a call, and a return instruction. In other cases, the register does not have a fixed meaning or fixed value.
- There are three one -person condition Codes : Zf,sf,of, which hold the most recent arithmetic or information about the hero caused by the rocky instruction.
- The program counter PC holds the address of the currently executing instruction.
4. Memory
The Y86 program uses virtual addresses to refer to memory locations, and hardware and operating system software unite to translate virtual addresses into actual or physical addresses
5. Status Code STAT
It indicates the overall state of the program execution, indicating whether it is functioning correctly or that an exception has occurred.
Second, Y86 directive
The Y86 instruction set is basically a subset of the IA32 instruction set, including only four-byte integer operations, with less addressing and fewer operations.
Refer to the 232 page of the textbook for the reference and byte encoding of sinks.
1.MOVL instruction
IA32 's MOVL directive is divided into four types:
irmovl,rrmovl,mrmovl,rmmovl
The preceding two letters are in the format of the specified source operand and the destination operand explicitly, the first bit is the source operand, and the second bit is the destination operand.
(1) Number of source operations
Can be:
i-立即数r-寄存器m-存储器
(2) Purpose of operation
Can be:
r-寄存器m-存储器
※ The memory reference method here is a simple base address and offset form, and the addressing method does not support the scaling of the second variable address register and any register value.
※ Two operands cannot be from the memory, nor allow the immediate number to be transmitted to the memory.
2. Four integer operation instructions
addl 加subl 减andl 与xorl 异或
And they operate only on register data (as distinct from IA32, which also allows these operations on the memory data).
These instructions will set up three condition codes :
ZF-零 SF-符号OF-溢出
3. Seven Jump Commands--branch control
jmp 直接跳转jle(SF^OF)|ZF 有符号数≤jl SF^OF 有符号<je ZF 相等/零jne ~ZF 不相等/非零jge ~(SF^OF) 有符号≥jg ~(SF^OF)&~ZF 有符号>
4. Six Conditional delivery Instructions
cmovlecmovlcmovecmovnecmovgecmovg
The format of these instructions is the same as the Register-register transfer Directive , but the value of the destination register is updated only if the condition code satisfies the required constraint RRMOVL.
5.call and RET
The call instruction returns the address to the stack, and then jumps to the destination address, which is returned from such a procedure invocation.
6.PUSHL and POPL
Implement in-stack and out-stack
7.halt instruction
The halt instruction stops the execution of the instruction, which causes the processor to stop and the status code to be set to HLT.
The analogy ia32:hlt directive is similar, but the IA32 application does not allow this instruction because it causes the entire system to pause.
Third, byte-level encoding of instructions
Each instruction requires a range of 1-6 bytes, and the first byte of each instruction indicates the type of instruction .
1. First byte
This byte is divided into two parts, each part 4 bits:
- High four-bit: Code section, domain value is 0~0xb
- Fourth bit: Functional part, function value is only useful if a set of related instructions is shared with one code.
For example: the No. 233 page of the textbook, the function Code of the Y86 instruction set:
The code portion of the integer operation is 6, the functional part distinguishes ADDL,SUBL,ANDL,XORL
The code portion of the branch instruction is 7.
The code portion of the delivery instruction is 2.
It's important to note that RRMOVL is in the delivery instructions, which says they have the same instruction code.
Each of the 8 program registers has a corresponding 0~7 register identifier , and the program register exists in a register file in the CPU, which is a small, random-access memory with the Register ID as the address.
When you need to indicate that no registers should be accessed, use the ID value 0xF to indicate
2. Some require extra bytes (1) Additional Register indicator bytes
Specify one or two registers, such as RA or RB.
- Without a register operand, such as branch instruction and call instruction, there is no register designator byte.
- An instruction that requires only one register operand (IRMOVL,PUSHL,POPL) instructs the other register to subscript character to 0xF
(2) Additional 4-byte constant numbers
The use of this word:
1.irmovl的立即数数据2.rmmol和mrmovl的地址指示符的偏移量3.分支指令和调用指令的目的地址
Precautions
1.分支指令和调用指令的目的地址是一个绝对地址2.所有整数采用小端法编码
※ Important properties of instruction set:
Byte encoding must have a unique explanation
Exercise 4.1: This problem only need to follow the instructions to encode the values of each bit to correspond, such as the first line, IRMOVL instruction is 30f, the purpose of the operation is%EBX, check the table is 3, the source operation is immediately number 15, converted to 16 into the xx xx 0f, the small-end method is expressed as 0f 00 00 00, combined together that is 30f30f000000.
Exercise 4.2: This problem should be careful to divide the numbers into different instructions.
Iv. Y86 anomalies 1. Possible value of status code stat
Stat describes the overall state of the program execution
1. AOK 正常操作2. HLT 处理器执行halt指令3. ADR 遇到非法地址4. INS 遇到非法指令
2. When an exception occurs?
The y86--processor stops running instructions.
More complete? Call an exception handler
V. Y86 procedures
See textbook 第238-239 page for specific examples
In contrast to the Y86 and IA32 codes, they are essentially the same, but:
The difference between 1.y86 and IA32
1.Y86有时需要两条指令来完成IA32一条指令就能完成的事2.Y86没有伸缩寻址模式
2. Note Some of the following:
(1) The command indicates where the code or data should be placed, and how it should be aligned
(2) to "." The beginning is the assembler command
(3) The only tool for creating Y86 code is the assembler, so programmers must perform tasks that would normally be done to compilers, linker, and runtime systems.
Vi. details of some Y86 directives
Specifically POPL and PUSHL, there are two different conventions when pressing/ejecting the stack pointer%esp:
1.压入/弹出%esp的原始值2.压入/弹出%esp-/+4后的值
After testing, it is found that the default press-in pops up the original values .
PUSHL There is ambiguity between the different x86 models, but POPL does not.
Section II Logic Design and hardware control Language HCL
In electronic circuits, the logic 1 is represented by a high voltage of about 1.0V, and the logic 0 is represented by a low voltage of about 0.0V.
First, the logic gate
1. The output generated by the logic gates is a Boolean function that equals their input bit value.
2.
AND &&OR ||NOT !
3. The logic gate operates only on the number of individual bits , not the entire word.
4. The logic gate is always active, and the input change output quickly follows the change.
Ii. combinational Circuits and HCl Boolean expressions
Combinational logic circuit corresponding to EDA learning
1. Limitations when building compute blocks (combinational circuits)
- Outputs of two or more logic gates cannot be connected together
- Must have no ring
2. The difference between logical expressions in combinational logic circuits and C language
- The output of the combined circuit will continue to respond to input changes, and the C language expression is evaluated only when it is encountered during execution
- The logic gate operates only on 0 and 1, the arguments in the C language expression can be any integer, 0 is false, not 0 is true
- The logical expression of C may be partially evaluated
Three, word-level combination circuit and HCL integer expression
There are a few bits and pieces of knowledge that need to be noticed:
- All word-level signals are declared as int, and the size of the word is not specified
The multiplexed function is described by a case expression, in the following format:
[select_1 : expr_1select_2 : expr_2……]
Logically, these selection expressions are evaluated sequentially .
- The selection expression is 1 o'clock, which means that if no previous case is selected, select this case
Allow non-mutex between different selection expressions
Iv. Set Relationship
The general format for judging set relationships is:
in {iexpr1,iexpr2,...,iexprk}
IEXPR, etc. are all integer expressions.
V. Memory and Clock
Sequential logic circuit corresponding to EDA learning
1. Two types of memory devices for sequential circuits:
(1) Clock Register (register): stores a single bit or word.
(2) Random access storage (for short): store multiple words, use the address to choose which word to read/write.
The registers are divided into "hardware registers" and "program registers".
2.Y86 processor
It will save the program counter PC with the clock register, the condition code CC and the program status Stat.
This section of the study compares the rules of the Verilog language learned in the EDA course, much the same, but pay attention to the migration--the operation that corresponds to the instruction in place.
The sequential implementation of the third section Y86
SEQ Processor
First, the process of organizing into phase (i) six basic stages:
- Take a finger
- Decoding
- Perform
- Visit
- Write back
- Update pc
Each phase of the implementation of the content is shown in page 250, according to each step of the calculation of the topic in the 253-page Exercise 4.11, the most important thing to do this problem is to pay attention to the meaning of each character represents what, in order to do the correct calculation. This problem is not difficult, is a bit of trouble, more read more understanding.
(ii) The specific framework is divided into four categories: 1. For OPL (integer and logical Operations), RRMOVL (register-register transfer) and IRMOVL (Immediate-register-transfer) 2. For RMMOVL and Mrmovl3. For the PUSHL and Popl4. For jump, call and ret two , SEQ hardware structure 1.SEQ Abstract view of the drawing:
- The program counter is placed in the register and is located in the lower left corner of the PC.
- The information flows with the line, the direction is first upward then to the right
- Feedback ancestors on the right down
- The processing of all hardware units is done in one clock cycle.
- Light gray squares indicate hardware units
- The control logic block is represented by a gray rounded rectangle.
- The name of the line is indicated in the white ellipse.
- Thin wire for data connections with a width of word length or narrower
- Single bit connection with dashed line
2. The hardware unit is associated with each processing phase
There are six basic stages, see above. Refer to the 258-page diagram for specific links.
Iii. timing of SEQ
The SEQ implementation includes combination logic and two memory devices :
1.时钟寄存器——程序计数器和条件码寄存器2.随机访问存储器——寄存器文件、指令存储器和数据存储器
For the five hardware units mentioned above, it can be divided into two categories:
1.组合逻辑——指令存储器2.时序——剩下四个
The remaining four:
条件码寄存器——只在执行整数运算指令时装载数据存储器——只在执行rmmovl、pushl或call时写入寄存器文件——两个写端口允许每个时钟周期更新两个程序寄存器。特殊寄存器?0xF表示此端口不应执行写操作。
Organizational principles under the ※y86 instruction set:
- The processor never needs to read the state updated by the instruction in order to complete the execution of an instruction.
The summary is that the clock is used to control the updating of the state elements, and the values are propagated by the combinatorial logic.
Iv. realization of the SEQ stage
Constants that must be explicitly referenced in the control logic:
- NOP instruction: pc+1, nothing else is changed
Halt directive: Causes the processor state to become hlt, causing it to stop running
1. Taking the finger stageTake the PC as the first byte and read 6 bytes.
Two logical blocks (separated from the first byte, four bits each)
icode-指令代码ifun-指令功能
Three-bit signals (based on icode values)
instr_valid-发现不合法的指令need_regids-包含寄存器指示符字节吗need_valC-包括常数字吗
The latter five bytes are the combined encoding of the Register designator byte and the constant number.
2. Decoding and writeback phase
All need to access the register file, according to the case of four ports, determine which register should be read to generate the signal Vala, VALB
3. Implementation phase
(1) including the Arithmetic/logic unit ALU, the output is Vale.
Alu is often used as an adder
(2) including the condition Code register
0, sign, overflow, generate signal set_cc
4. The stage of the visit
- Read or write program data.
Two data blocks generate the memory address and the value of the memory input evidence, and two generate control signals indicating whether to read or write.
- Based on Icode,imem_error,instr_valid,dmem_error, the status code stat is calculated from the result of the instruction execution.
5. Update PC Stage
The new value of the program counter is generated. Resources
Textbooks.
Experiment
After you run the make command
To view the contents of the directory, you can see only. ys files
After compiling with the make all command
After compiling and viewing the contents of the directory, you can see that there are already compiled. yo files that can be viewed with vim
The code in Figure 4-7 of the No. 239 page of the textbook, called Asum.yo in the system, prints its contents on the screen:
It can be seen that the results are consistent with the 240 pages of the textbook.
Textbook page No. 251 of Figure 4-17, I first used to build a 417.ys enter after entering:
Then compile with make 417.yo and use Vim to enter 417.yo after compiling.
Chapter fourth Processor Architecture section Y86 instruction set architecture One, programmer visible State 1. Meaning:
Each instruction will read or modify portions of the processor state
2. "Programmer":
It can be the person who writes the program with the assembler code, or the compiler that produces the machine-level code.
3. Specific processor status: similar to IA32
- There are 8 program registers ,%EAX,%ECX,%EDX,%EBX,%ESI,%EDI,%ESP,%EBP
- Each program register of the processor stores one word
- The register%ESP is used as a stack pointer by a stack, a stack, a call, and a return instruction. In other cases, the register does not have a fixed meaning or fixed value.
- There are three one -person condition Codes : Zf,sf,of, which hold the most recent arithmetic or information about the hero caused by the rocky instruction.
- The program counter PC holds the address of the currently executing instruction.
4. Memory
The Y86 program uses virtual addresses to refer to memory locations, and hardware and operating system software unite to translate virtual addresses into actual or physical addresses
5. Status Code STAT
It indicates the overall state of the program execution, indicating whether it is functioning correctly or that an exception has occurred.
Second, Y86 directive
The Y86 instruction set is basically a subset of the IA32 instruction set, including only four-byte integer operations, with less addressing and fewer operations.
Refer to the 232 page of the textbook for the reference and byte encoding of sinks.
1.MOVL instruction
IA32 's MOVL directive is divided into four types:
irmovl,rrmovl,mrmovl,rmmovl
The preceding two letters are in the format of the specified source operand and the destination operand explicitly, the first bit is the source operand, and the second bit is the destination operand.
(1) Number of source operations
Can be:
i-立即数r-寄存器m-存储器
(2) Purpose of operation
Can be:
r-寄存器m-存储器
※ The memory reference method here is a simple base address and offset form, and the addressing method does not support the scaling of the second variable address register and any register value.
※ Two operands cannot be from the memory, nor allow the immediate number to be transmitted to the memory.
2. Four integer operation instructions
addl 加subl 减andl 与xorl 异或
And they operate only on register data (as distinct from IA32, which also allows these operations on the memory data).
These instructions will set up three condition codes :
ZF-零 SF-符号OF-溢出
3. Seven Jump Commands--branch control
jmp 直接跳转jle(SF^OF)|ZF 有符号数≤jl SF^OF 有符号<je ZF 相等/零jne ~ZF 不相等/非零jge ~(SF^OF) 有符号≥jg ~(SF^OF)&~ZF 有符号>
4. Six Conditional delivery Instructions
cmovlecmovlcmovecmovnecmovgecmovg
The format of these instructions is the same as the Register-register transfer Directive , but the value of the destination register is updated only if the condition code satisfies the required constraint RRMOVL.
5.call and RET
The call instruction returns the address to the stack, and then jumps to the destination address, which is returned from such a procedure invocation.
6.PUSHL and POPL
Implement in-stack and out-stack
7.halt instruction
The halt instruction stops the execution of the instruction, which causes the processor to stop and the status code to be set to HLT.
The analogy ia32:hlt directive is similar, but the IA32 application does not allow this instruction because it causes the entire system to pause.
Third, byte-level encoding of instructions
Each instruction requires a range of 1-6 bytes, and the first byte of each instruction indicates the type of instruction .
1. First byte
This byte is divided into two parts, each part 4 bits:
- High four-bit: Code section, domain value is 0~0xb
- Fourth bit: Functional part, function value is only useful if a set of related instructions is shared with one code.
For example: the No. 233 page of the textbook, the function Code of the Y86 instruction set:
The code portion of the integer operation is 6, the functional part distinguishes ADDL,SUBL,ANDL,XORL
The code portion of the branch instruction is 7.
The code portion of the delivery instruction is 2.
It's important to note that RRMOVL is in the delivery instructions, which says they have the same instruction code.
Each of the 8 program registers has a corresponding 0~7 register identifier , and the program register exists in a register file in the CPU, which is a small, random-access memory with the Register ID as the address.
When you need to indicate that no registers should be accessed, use the ID value 0xF to indicate
2. Some require extra bytes (1) Additional Register indicator bytes
Specify one or two registers, such as RA or RB.
- Without a register operand, such as branch instruction and call instruction, there is no register designator byte.
- An instruction that requires only one register operand (IRMOVL,PUSHL,POPL) instructs the other register to subscript character to 0xF
(2) Additional 4-byte constant numbers
The use of this word:
1.irmovl的立即数数据2.rmmol和mrmovl的地址指示符的偏移量3.分支指令和调用指令的目的地址
Precautions
1.分支指令和调用指令的目的地址是一个绝对地址2.所有整数采用小端法编码
※ Important properties of instruction set:
Byte encoding must have a unique explanation
Exercise 4.1: This problem only need to follow the instructions to encode the values of each bit to correspond, such as the first line, IRMOVL instruction is 30f, the purpose of the operation is%EBX, check the table is 3, the source operation is immediately number 15, converted to 16 into the xx xx 0f, the small-end method is expressed as 0f 00 00 00, combined together that is 30f30f000000.
Exercise 4.2: This problem should be careful to divide the numbers into different instructions.
Iv. Y86 anomalies 1. Possible value of status code stat
Stat describes the overall state of the program execution
1. AOK 正常操作2. HLT 处理器执行halt指令3. ADR 遇到非法地址4. INS 遇到非法指令
2. When an exception occurs?
The y86--processor stops running instructions.
More complete? Call an exception handler
V. Y86 procedures
See textbook 第238-239 page for specific examples
In contrast to the Y86 and IA32 codes, they are essentially the same, but:
The difference between 1.y86 and IA32
1.Y86有时需要两条指令来完成IA32一条指令就能完成的事2.Y86没有伸缩寻址模式
2. Note Some of the following:
(1) The command indicates where the code or data should be placed, and how it should be aligned
(2) to "." The beginning is the assembler command
(3) The only tool for creating Y86 code is the assembler, so programmers must perform tasks that would normally be done to compilers, linker, and runtime systems.
Vi. details of some Y86 directives
Specifically POPL and PUSHL, there are two different conventions when pressing/ejecting the stack pointer%esp:
1.压入/弹出%esp的原始值2.压入/弹出%esp-/+4后的值
After testing, it is found that the default press-in pops up the original values .
PUSHL There is ambiguity between the different x86 models, but POPL does not.
Section II Logic Design and hardware control Language HCL
In electronic circuits, the logic 1 is represented by a high voltage of about 1.0V, and the logic 0 is represented by a low voltage of about 0.0V.
First, the logic gate
1. The output generated by the logic gates is a Boolean function that equals their input bit value.
2.
AND &&OR ||NOT !
3. The logic gate operates only on the number of individual bits , not the entire word.
4. The logic gate is always active, and the input change output quickly follows the change.
Ii. combinational Circuits and HCl Boolean expressions
Combinational logic circuit corresponding to EDA learning
1. Limitations when building compute blocks (combinational circuits)
- Outputs of two or more logic gates cannot be connected together
- Must have no ring
2. The difference between logical expressions in combinational logic circuits and C language
- The output of the combined circuit will continue to respond to input changes, and the C language expression is evaluated only when it is encountered during execution
- The logic gate operates only on 0 and 1, the arguments in the C language expression can be any integer, 0 is false, not 0 is true
- The logical expression of C may be partially evaluated
Three, word-level combination circuit and HCL integer expression
There are a few bits and pieces of knowledge that need to be noticed:
- All word-level signals are declared as int, and the size of the word is not specified
The multiplexed function is described by a case expression, in the following format:
[select_1 : expr_1select_2 : expr_2……]
Logically, these selection expressions are evaluated sequentially .
- The selection expression is 1 o'clock, which means that if no previous case is selected, select this case
Allow non-mutex between different selection expressions
Iv. Set Relationship
The general format for judging set relationships is:
in {iexpr1,iexpr2,...,iexprk}
IEXPR, etc. are all integer expressions.
V. Memory and Clock
Sequential logic circuit corresponding to EDA learning
1. Two types of memory devices for sequential circuits:
(1) Clock Register (register): stores a single bit or word.
(2) Random access storage (for short): store multiple words, use the address to choose which word to read/write.
The registers are divided into "hardware registers" and "program registers".
2.Y86 processor
It will save the program counter PC with the clock register, the condition code CC and the program status Stat.
This section of the study compares the rules of the Verilog language learned in the EDA course, much the same, but pay attention to the migration--the operation that corresponds to the instruction in place.
The sequential implementation of the third section Y86
SEQ Processor
First, the process of organizing into phase (i) six basic stages:
- Take a finger
- Decoding
- Perform
- Visit
- Write back
- Update pc
Each phase of the implementation of the content is shown in page 250, according to each step of the calculation of the topic in the 253-page Exercise 4.11, the most important thing to do this problem is to pay attention to the meaning of each character represents what, in order to do the correct calculation. This problem is not difficult, is a bit of trouble, more read more understanding.
(ii) The specific framework is divided into four categories: 1. For OPL (integer and logical Operations), RRMOVL (register-register transfer) and IRMOVL (immediate count-register transfer)
2. For RMMOVL and MRMOVL
3. For PUSHL and POPL
4. For jump, call and RET
These four types can be set in a frame.
Second, the SEQ hardware structure 1.SEQ Abstract view of the drawing:
- The program counter is placed in the register and is located in the lower left corner of the PC.
- The information flows with the line, the direction is first upward then to the right
- Feedback ancestors on the right down
- The processing of all hardware units is done in one clock cycle.
- Light gray squares indicate hardware units
- The control logic block is represented by a gray rounded rectangle.
- The name of the line is indicated in the white ellipse.
- Thin wire for data connections with a width of word length or narrower
- Single bit connection with dashed line
2. The hardware unit is associated with each processing phase
There are six basic stages, see above. Refer to the 258-page diagram for specific links.
Iii. timing of SEQ
The SEQ implementation includes combination logic and two memory devices :
1.时钟寄存器——程序计数器和条件码寄存器2.随机访问存储器——寄存器文件、指令存储器和数据存储器
For the five hardware units mentioned above, it can be divided into two categories:
1.组合逻辑——指令存储器2.时序——剩下四个
The remaining four:
条件码寄存器——只在执行整数运算指令时装载数据存储器——只在执行rmmovl、pushl或call时写入寄存器文件——两个写端口允许每个时钟周期更新两个程序寄存器。特殊寄存器?0xF表示此端口不应执行写操作。
Organizational principles under the ※y86 instruction set:
- The processor never needs to read the state updated by the instruction in order to complete the execution of an instruction.
The summary is that the clock is used to control the updating of the state elements, and the values are propagated by the combinatorial logic.
Iv. realization of the SEQ stage
Constants that must be explicitly referenced in the control logic:
- NOP instruction: pc+1, nothing else is changed
Halt directive: Causes the processor state to become hlt, causing it to stop running
1. Taking the finger stageTake the PC as the first byte and read 6 bytes.
Two logical blocks (separated from the first byte, four bits each)
icode-指令代码ifun-指令功能
Three-bit signals (based on icode values)
instr_valid-发现不合法的指令need_regids-包含寄存器指示符字节吗need_valC-包括常数字吗
The latter five bytes are the combined encoding of the Register designator byte and the constant number.
2. Decoding and writeback phase
All need to access the register file, according to the case of four ports, determine which register should be read to generate the signal Vala, VALB
3. Implementation phase
(1) including the Arithmetic/logic unit ALU, the output is Vale.
Alu is often used as an adder
(2) including the condition Code register
0, sign, overflow, generate signal set_cc
4. The stage of the visit
- Read or write program data.
Two data blocks generate the memory address and the value of the memory input evidence, and two generate control signals indicating whether to read or write.
- Based on Icode,imem_error,instr_valid,dmem_error, the status code stat is calculated from the result of the instruction execution.
5. Update PC Stage
The new value of the program counter is generated.
Learning Summary
The content of this chapter is generally unfamiliar, looks very laborious, only to the textbook stumbling to do, the ability to migrate out is not enough, but the middle of the logic gate calculation of the part because the last semester has Verilog Language Foundation, learning can be used as an analogy, extrapolate, Thus the understanding of this part is relatively easy.
Resources
Textbooks.
Experiment
After you run the make command
To view the contents of the directory, you can see only. ys files
After compiling with the make all command
After compiling and viewing the contents of the directory, you can see that there are already compiled. yo files that can be viewed with vim
The code in Figure 4-7 of the No. 239 page of the textbook, called Asum.yo in the system, prints its contents on the screen:
It can be seen that the results are consistent with the 240 pages of the textbook.
Textbook page No. 251 of Figure 4-17, I first used to build a 417.ys enter after entering:
Then compile with make 417.yo and use Vim to enter 417.yo after compiling.
Reference, I saw Shang she summed up than I have more organized.
Information security system Design Fundamentals Fifth Week study summary------20135334 Zhao Yanglin