在我们设计出来前边三种CPU之后,我们来进行程序的编写。
所谓程序的编写,就是;利用我们写好的CPU,根据我们可执行的指令集,来编写一段程序,可一直用我们的CPU来完成。
首先,我们在写程序之前,确定你的CPU可以执行load,store,beq,jump,add几种基础指令,如果这几个都没有,那这个程序怕是也做不出来的。
在你希望实现的小系统中,一定有你的外围电路,它是将你外部输入的数据写入外存/数据存储器 中的,并将运算结果读出并显示或... 之后你的指令在开始时寄存器堆中可以预先有操作数,也可以通过指令读入。程序在开始前进行load将数据从数据存储器中读入寄存器堆中,最后再从寄存器堆中用store写会到数据寄存器中。在运算中有判断时就使用beq来完成,直接跳转一般都在beq跳转到的位置进行有效操作完的下一条指令,为了实现如C语言中的if语句。
最终你的指令是写成一个case语句中或者写成一个.coe文件的,coe文件直接写入数据存储器中,
例如
32'd0 : instruction <= 32'b000001_00001_00100_0000000000000000; //1 1 4 000 lw
32'd1 : instruction <= 32'b000000_00000_00001_00010_00000_000000; //0 0 1 2 0 0 add
32'd2 : instruction <= 32'b000001_00010_00101_0000000000000000; //1 2 5 000 lw
32'd3 : instruction <= 32'b000000_00000_00010_00011_00000_000000; //0 0 2 3 0 0 add
32'd4 : instruction <= 32'b000001_00011_00110_0000000000000000; //1 3 6 000 lw
32'd5 : instruction <= 32'b000000_00011_00010_01101_00000_000001; //0 3 2 13 0 13 sub
32'd6 : instruction <= 32'b000101_00110_01101_0000000000000001; //5 6 13 6 beq
32'd7 : instruction <= 32'b000111_00000000000000000000000000; //7 0 j
32'd8 : instruction <= 32'b000101_00110_01101_0000000000000110; //5 6 13 6 beq
32'd9 : instruction <= 32'b000000_00000_00111_01000_00000_000000; //0 0 7 8 0 0 add
32'd10 : instruction <= 32'b000000_00000_01000_01001_00000_000000; //0 0 8 9 0 0 add
32'd11 : instruction <= 32'b000000_00000_01001_01010_00000_000000; //0 0 9 10 0 0 add
32'd12 : instruction <= 32'b000000_00000_01010_01011_00000_000000; //0 0 10 11 0 0 add
32'd13 : instruction <= 32'b000101_00110_01101_0000000000000110; //5 6 13 6 beq
32'd14 : instruction <= 32'b000101_00110_00010_0000000000000111; //5 6 2 7 beq
32'd15 : instruction <= 32'b000101_00110_00011_0000000000001000; //5 6 3 8 beq
32'd16 : instruction <= 32'b000101_00110_00111_0000000000001001; //5 6 7 9 beq
32'd17 : instruction <= 32'b000101_00110_01000_0000000000001010; //5 6 8 10 beq
32'd18 : instruction <= 32'b000101_00110_01001_0000000000001010; //5 6 9 10 beq
32'd19 : instruction <= 32'b000101_00110_01010_0000000000001010; //5 6 10 10 beq
32'd20 : instruction <= 32'b000000_00100_00101_01100_00000_000000; //0 4 5 12 0 0 add
32'd21 : instruction <= 32'b000111_00000000000000000000011110; //7 30 j
32'd22 : instruction <= 32'b000000_00100_00101_01100_00000_000001; //0 4 5 12 0 1 sub
32'd23 : instruction <= 32'b000111_00000000000000000000011110; x //7 30 j
32'd24 : instruction <= 32'b000000_00100_00101_01100_00000_000010; //0 4 5 12 0 2 and
32'd25 : instruction <= 32'b000111_00000000000000000000011110; //7 30 j
32'd26 : instruction <= 32'b000000_00100_00101_01100_00000_000011; //0 4 5 12 0 3 or
32'd27 : instruction <= 32'b000111_00000000000000000000011110; //7 30 j
32'd28 : instruction <= 32'b000000_00100_00101_01100_00000_000100; //0 4 5 12 0 4 nor
32'd29 : instruction <= 32'b000111_00000000000000000000011110; //7 30 j
32'd30 : instruction <= 32'b000010_00000_01100_0000000000000000; //2 0 13 000 sw
32'd31 : instruction <= 32'b000111_00000000000000000000000000; //7 0 j */
或者.coe文件
memory_initialization_radix = 2 ;
memory_initialization_vector =
10001000001000100000000000000010,
00010100001000100000000000000010,
00001000000000000000000000000000,
10001000001000110000000000000000,
00010100011000100000000000000010,
10101100001001000000000100000010,
00001000000000000000000000000000,
10101100001001010000000100000010,
00001000000000000000000000000000,
最终烧录验证就实现了用CPU跑一个小程序了。
全部0条评论
快来发表一下你的评论吧 !