Step 5 of Self-writing CPU (5)-Implementation of testing logic, shift and empty commands

Source: Internet
Author: User

I will upload my new book "Write CPU by myself" (not published yet). Today is 19th articles. I try to write them every Thursday.


5.6 test procedure 1-test the logical operation Implementation Effect

Write the following test program to check whether the logic operation command is implemented correctly. The file name is inst_rom.s. The test program source file is available in the Code \ chapter5_2 \ asmtest \ logicinsttest directory of the attached CD.

.org 0x0.global _start.set noat_start:lui  $1,0x0101           # $1 = 0x01010000ori  $1,$1,0x0101        # $1 = $1 | 0x0101 = 0x01010101ori  $2,$1,0x1100        # $2 = $1 | 0x1100 = 0x01011101or   $1,$1,$2            # $1 = $1 | $2     = 0x01011101andi $3,$1,0x00fe        # $3 = $1 & 0x00fe = 0x00000000and  $1,$3,$1            # $1 = $3 & $1     = 0x00000000xori $4,$1,0xff00        # $4 = $1 ^ 0xff00 = 0x0000ff00xor  $1,$4,$1            # $1 = $4 ^ $1     = 0x0000ff00nor  $1,$4,$1            # $1 = $4 ~^ $1    = 0xffff00ff

The expected execution result of the program is provided in the program annotation, where the changes in the register $1-$4 are shown. Set the inst_rom.s file to bin2mem.exe, makefile, and ram. lD these three files are copied to the same directory in the Ubuntu virtual machine, open the terminal, run the CD command to enter the directory, and then enter make all to get the inst_rom.data file used for Modelsim simulation.

Create a new project in Modelsim, add all. V files under the Code \ chapter5_2 directory of the CD, and compile the project. Copy the above inst_rom.data file to the directory of The Modelsim project to perform simulation. The above simulation steps will not be repeated later.

Modelsim simulation results 5-16 show that regs [1], regs [2], regs [3], and regs [4] are registers $1, $2, $3, and $4, respectively, observe the changes in the values of these four registers and we can see that they are as expected. Therefore, openmips correctly implements logical operation commands.


5.7 Test Procedure 2-Test the effects of shift operations and empty instructions

Write the following test program to check whether the shift operation and the empty command are implemented correctly. The file name is still named inst_rom.s, and the test program source file is available in the Code \ chapter5_2 \ asmtest \ shiftinsttest directory on the CD-Rom.

.org 0x0.set noat.global _start_start:lui   $2,0x0404    # $2 = 0x04040000ori   $2,$2,0x0404 # $2 = 0x04040000 | 0x0404 = 0x04040404ori   $7,$0,0x7ori   $5,$0,0x5ori   $8,$0,0x8syncsll   $2,$2,8      # $2 = 0x40404040 sll 8  = 0x04040400sllv  $2,$2,$7     # $2 = 0x04040400 sll 7  = 0x02020000srl   $2,$2,8      # $2 = 0x02020000 srl 8  = 0x00020200srlv  $2,$2,$5     # $2 = 0x00020200 srl 5  = 0x00001010nopprefsll   $2,$2,19     # $2 = 0x00001010 sll 19 = 0x80800000ssnopsra   $2,$2,16     # $2 = 0x80800000 sra 16 = 0xffff8080srav  $2,$2,$8     # $2 = 0xffff8080 sra 8  = 0xffffff80 

The program's expected execution results are given in the program's annotations, mainly the changes in register $2. Modelsim simulation result 5-17 shows that openmips correctly implements the shift operation instruction and empty instruction by observing the changes in register $2.


Conclusion 5.8

This chapter first analyzes the data-related problems in the pipeline, and then uses the data push method to solve the data-related problems, and then modifies openmips, it supports logic, shift operations, and empty commands. It mainly modifies the ID module of the decoding stage and the ex module of the execution stage. The ID module adds Decoding of new commands and the ex module adds support for new computing types.


Please pay attention to the implementation of the mobile operation commands from the next time!

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.