Will be uploaded I wrote a new book, "Write Your Own CPU" (not yet published), today is the 20th, I try to four weekly
This chapter will implement the mobile operation instructions, first in section 6.1 describes the MIPS32 instruction set schema defined in the format of the mobile operation instructions, and then in the 6.2 section gives the implementation of the mobile operation instructions, introduced the modified Data flow chart, the emergence of the relevant problems and solutions, And the structure diagram of the modified openmips system is given. The detailed modification process is listed in section 6.3. This chapter concludes with a test program to verify that the move operation instructions are implemented correctly.
6.1 Description of the mobile operation instructions
The MIPS32 instruction set schema defines a total of 6 mobile operations directives: MOVN, Movz, Mfhi, Mthi, Mflo, Mtlo, and the last 4 instructions refer to the Read and write operation of the special Register Hi, lo, as of this chapter, Our Openmips processor implements only 32 general-purpose registers, as well as PCs, and all instructions operate on 32 general-purpose registers, and no special registers are involved, and this chapter implements the special registers of Hi and lo.
The HI and lo registers are used to save multiplication and division results. When used to save the multiplication result, the Hi register holds the high 32 bits of the result, the LO register holds the low 32 bits of the result, and when used to hold the division result, the Hi register saves the remainder, the LO register depositary. Further instructions are described in the following chapter, "Implementation of arithmetic operations directives".
The 6 move operation instructions are shown in format 6-1.
As shown in Figure 6-1, these 6 instructions are all R-type directives, and the instruction code is 6 ' b000000, that is, the special class instruction, at the same time, the instruction 6-10bit is 0, you can determine according to the value of the 0-5bit function code in the instruction is what kind of instruction. The usage and functions of each instruction are described below.
- When the function code is 6 ' b001011, the MOVN instruction is indicated
Instruction usage: MOVN Rd, RS, RT
The instruction function is: if rt≠0 then rd <-RS, the value of the General register address is RT, if not zero, then the value of the general register with the address of RS is assigned to the General register with the Address Rd, whereas the General register with the address of Rd remains the same. MOVN is the meaning of move Conditional on not zero.
- When the function code is 6 ' b001010, the MOVZ instruction is indicated
Instruction usage: Movz Rd, RS, RT
The directive functions as follows: If RT = 0 Then rd <-rs, contrary to the above MOVN directive, the value of the general register with the address RT is determined, if zero, then the value of the universal register with the address of RS is assigned to the universal register with the Address Rd, and vice versa, Keep the universal register with Address Rd unchanged. Movz is the meaning of move Conditional on zero.
- When the function code is 6 ' b010000, the MFHI instruction is indicated
Instruction usage is: MFHI Rd
The directive functions as: Rd <-Hi, assigning the value of the special register hi to the general register with the address Rd.
- When the function code is 6 ' b010010, the Mflo instruction is indicated
Instruction usage is: Mflo Rd
The directive functions as: Rd <-Lo, assigning the value of the special register lo to the general register with the address Rd.
- When the function code is 6 ' b010001, the mthi instruction is indicated
Instruction Usage: Mthi RS
The instruction function is: Hi <-RS, assigns the value of the universal register with the address RS to the Special Register hi.
- When the function code is 6 ' b010011, the mtlo instruction is indicated
Instruction Usage: Mtlo RS
The directive functions as: Lo <-RS, assigns the value of the universal register with the address RS to the Special register lo.