Write yourself the sixth phase of CPU (2)--the implementation of mobile operation instructions

Source: Internet
Author: User

Will be uploaded I wrote a new book, "Write Your Own CPU" (not yet published), today is the 21st, I try to four weekly


6.2The idea of moving operation instruction Realization6.2.1Implementation Ideas

This6The move instructions can be divided into two categories: one is not involved in special registersHI,LOthe instructions, includingMOVN,MovzAnd the other involves special registers.HI,LOthe instructions, includingMfhi,Mflo,Mthi,Mtlo. The first class is very good realization, the basic idea and the first5similar to implementing the logic and shift instructions, just modify theID,EXmodule. The latter category relates to special registersHI,LO, you need toopenmipsAddHI,LOregisters, and the corresponding read/write control. The following are the respective implementation ideas.

1,movn,movz instruction Realization Idea

Similar to the implementation process of Chapter 5 logic, shift operation instructions.

      (1 The operation type is given in the decoding phase alusel_o aluop_o , the destination register address to write wd_o The value of the signal, while reading the address as Span style= "Font-family:times New Roman" >rs rt rt 0

(2) The execution stage, based on the incoming signal, determines the information of the final destination register (including: Write, write the destination register address, write the value), and pass the information to the storage stage.

(3) The above information will be passed to the write-back phase. Finally, modify the destination register based on this information, or make no changes.

2,mthi,mtlo instruction Realization Idea

      This 2 instructions need to be written hi lo hi lo The write operation of the register is placed in the write-back phase.

      (1 In the decoding phase according to the instruction, the operation type alusel_o aluop_o rs mthi , mtlo does not write universal registers, so wreg_o wd_o Span style= "font-family: Arial" to 0

(2) in the execution phase, determine what to write HI,LO Register, and the value to write, and pass this information to the storage stage.

(3) This information is transferred to the write-back stage at the time of the visit.

(4) The write-back phase modifies The value of the HI and LO registers based on this information.

3,mfhi,mflo instruction Realization Idea

These 2 instructions need to read HI,LO registers, which are designed to be read at the execution stage.

      (1 In the decoding phase according to the instruction, the operation type alusel_o aluop_o value, At the same time because there is a purpose register to write, so wreg_o writeenable , wd_o for instruction rd

(2) The value of the HI or LO Register isobtained during the execution phase as the data to be written to the destination register, and the information is passed to the storage stage.

(3) This information is transferred to the write-back stage at the time of the visit.

(4) The write-back phase modifies the purpose register based on this information.

After adding the move operation instruction, the flow graph 6-2 is shown.


Comparison diagram 6-2 and figure 5-7 can be found to have the following differences.

    • The HILO Register module is added, and the module is placed in the writeback phase.
    • The value of the HIandLO registers is passed to the execution stage, and a selection module is added during the execution phase to select the data to participate in the operation, and if it is the mfhi,mflo instruction, then it will choose to pass over the The value of the HIandLO registers.

6.2.2resolution of new data-related situations

Further considerationMfhi,MfloThe process of instruction, which2instructions are read at the pipelining execution stageHI,LOthe value of the register, if directly using theHILOmodule gives theHI,LOThe value of the register may not be correctHI,LOThe value of the register, because the instruction at the time of the fetch, write-back phase is likely to be modifiedHI,LORegister, take the following procedure as an example.

1,    lui $1,0x0000          # $ = 0x000000002,    lui $2,0xffff          # $ = 0xffff00003,    mthi $                # hi = 0x000000 004.    Mthi $                # hi = 0x000000005,    mthi $                # hi = 0xffff00006,    mfhi $4                # $4 = 0xffff0000

Instructions3,4,5All to modifyHIRegister, when the instruction6when in the execution phase, the instruction5at the stage of the visit, the Directive4in the write-back phase, at which pointHIthe value of the register is the instruction3just write the0x00000000,HILOthe module is to pass this value to the execution stage, if this value is used, then it will be wrong, deviate from the program, the correct value should be the current stage of the instruction5the data to be written,6-3is shown.


      Déjà vu, isn't it? This is the data-related issue that was introduced in the previous chapter, and the workaround is to use data forward. The instruction to hi lo Register operation information is fed to the execution phase, and the execution phase is based on this information to determine Span style= "Font-family:times New Roman" >hi lo The correct value of the register.

To this end, the need to modify the flow diagram 6-4 , compared to figure 6-3, the main increase is the memory of the visit stage, write back to the stage of feedback to the implementation phase, input to the implementation phase of the selection module (shown in the rough line), If the mfhi,Mflo directives are in the execution phase , then the HI,LO is selected from the The correct value for the register.


6.2.3modification of the system structure

In order to implement the mobile operation instructions need to complement the openmips system structure, mainly modify the 6-5 shown.


There are three main aspects.

(1) The HILO module is added to implement the HI,LO registers.

(2) The execution phase of theEXthe module addswhilo_o,Hi_o,lo_ointerface, indicating whether to writeHILO, to writeHIthe value of the register, to writeLOthe value of the register. These three interfaces are passed out to theHI,LOThe Register's modification information isEx/mem,MEM,MEM/WBthree modules are passed to the write-back phase and are eventually passed toHILOmodule.

(3) The EX module inthe execution phase adds an input interface to the HI,LO registers, including to resolve HI , LO The data-related issues of the registers, and the interfaces introduced by the 6.3.3 section will be described in detail.

next time will introduce the implementation of the mobile operation instructions, and give the code, please pay attention!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.