I will upload my new book "Write CPU by myself". Today is 27th articles. I try to write them every Thursday.
The pre-sale addresses of China-pub are as follows (including directories, content descriptions, and preface ):
Http://product.china-pub.com/3804025
The pre-sale address of Amazon is as follows. You are welcome to watch it!
Http://www.amazon.cn/dp/b00mqkrlg8/ref=cm_sw_r_si_dp_5kq8tb1gyhja4
7.4 Test the implementation of simple arithmetic operation commands
This section uses experiments to check whether the modified Code implements simple arithmetic operation commands. The test program is as follows. The source file is the inst_rom.s file under the "Code \ chapter7_1 \ asmtest" directory attached to the book.
. Org 0x0. set noat. global _ start_start :######## Section 1: test the Add \ addi \ addiu \ Addu \ sub \ subu command ############### Ori $1, $8000x00008000 #$1 = 0x80000000 sll $1, $#$1 = 0 x Ori $1, $0010x80000010 #$1 = 0x8000 assign the initial value Ori $2 to $1, $00008000X#$2 = 0 x sll $2, $80000000 #$2 = 0x0001 Ori $2, $80000001X#$2 = 0 x grant the initial value Ori $3 to $2, $0000x00000000 #$3 = 0x00000011 Addu $3, $2, $1 #$3 = 0x$1 plus $2, unsigned addition Ori $3, $0000x00000000 #$3 = 0 x add $3, $2, $1 #$2 plus $1, signed addition, result overflow, so $3 should remain unchanged #$3 should be 0x00000000 sub $3, $1, $3 #$3 = 0x80000010 $1 minus $3, signed subtraction subu $3, $3, $2 #$3 = 0xf $3 minus $2, unsigned subtraction addi $3, $0000 #$3 = 0x11 $3 plus 2, signed addition Ori $3, $00000000X#$3 = 0 x addiu $3, $3, 0x8000 #$3 = 0xffff8000 $3 + 0xffff8000, unsigned addition ############ Section 2: test the SLT \ SLTU \ slti \ sltiu command ################# or $1, $ xFFFF #$1 = 0x0000ffff sll $1, $#$1 = 0xffff0000 assign initial values to $1 SLT $2, $1, $0 #$2 = 1 compare $1 with 0x0, signed SLTU $2, $1, $0 #$2 = 0 compare $1 with 0x0, unsigned comparison slti $2, $8000x#$2 = 1 Comparison $1 and 0xffff8000, signed comparison sltiu $2, $8000x#$2 = 1 Comparison $1 and 0xffff8000, unsigned comparison ############## section 3: test the clo \ clz command ############### lui $0000x00000000 #$1 = 0 x assign an initial value to $1 clo $ 2, $1 #$2 = 0x00000000 count the number of "1" before "0" in $1 clz $2, $1 #$2 = 0x00000020 count the number of "0" before "1" in $1 lui $1, 0 xFFFF #$1 = 0xffff0000 Ori $1, $ xFFFF #$1 = 0 xffffffff assign the initial value clz $2 to $1, $1 #$2 = 0x00000000 count the number of "0" before "1" in $1 clo $2, $1 #$2 = 0x00000020 count the number of "1" before "0" in $1 lui $1, 0xa100 #$1 = 0xa000000 assign the initial value clz $2 to $1, $1 #$2 = 0x00000000 count the number of "0" before "1" in $1 clo $2, $1 #$2 = 0x00000001 count the number of "1" before "0" in $1 lui $1100x11000000 #$1 = 0 x assign an initial value to $1 clz $2, $1 #$2 = 0x00000003 count the number of "0" before "1" in $1 clo $2, $1 #$2 = 0x00000000 count the number of "1" before "0" in $1 ################# four sections: test Mul, mult, and multu commands ############## Ori $1, $ xFFFF sll $1, $ Ori $1, $ xfffb #$1 =-5 assign the initial value Ori $2 to $1, $#$2 = 6 assign the initial value Mul $3 to $2, $1, $2 #$3 =-30 = 0xffffffe2 #$1 multiplied by $2, the low 32 bits of the result are saved to $3 mult $1, $2 # Hi = 0 xffffffff # Lo = 0xffffffe2 #$1 multiplied by $2. The signed multiplication result is saved to the HI and lo registers multu $1, $2 # Hi = 0x5 # Lo = 0xffffffe2 #$1 multiplied by $2. The result is unsigned multiplication and saved to hi and lo registers NOP.
The program prompts the expected results, including the inst_rom.s file, 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, you can obtain the command memory initialization file inst_rom.data for Modelsim simulation.
Create a new project in Modelsim, add all. V files under the CD Code \ chapter7_1 directory attached to this book, and compile the project. Copy the above inst_rom.data file to the directory of The Modelsim project for simulation. The simulation results 7-6, 7-7, 7-8, and 7-9 correspond to four sections in the test program.
The openmips code that implements simple arithmetic commands is as follows:
Http://download.csdn.net/detail/leishangwen/7801711
Step 7 of Self-writing CPU (4) -- verify the effect of simple arithmetic operation commands