在我們?cè)O(shè)計(jì)出來前邊三種CPU之后,我們來進(jìn)行程序的編寫。
所謂程序的編寫,就是;利用我們寫好的CPU,根據(jù)我們可執(zhí)行的指令集,來編寫一段程序,可一直用我們的CPU來完成。
首先,我們?cè)趯懗绦蛑?,確定你的CPU可以執(zhí)行l(wèi)oad,store,beq,jump,add幾種基礎(chǔ)指令,如果這幾個(gè)都沒有,那這個(gè)程序怕是也做不出來的。
在你希望實(shí)現(xiàn)的小系統(tǒng)中,一定有你的外圍電路,它是將你外部輸入的數(shù)據(jù)寫入外存/數(shù)據(jù)存儲(chǔ)器 中的,并將運(yùn)算結(jié)果讀出并顯示或... 之后你的指令在開始時(shí)寄存器堆中可以預(yù)先有操作數(shù),也可以通過指令讀入。程序在開始前進(jìn)行l(wèi)oad將數(shù)據(jù)從數(shù)據(jù)存儲(chǔ)器中讀入寄存器堆中,最后再?gòu)募拇嫫鞫阎杏胹tore寫會(huì)到數(shù)據(jù)寄存器中。在運(yùn)算中有判斷時(shí)就使用beq來完成,直接跳轉(zhuǎn)一般都在beq跳轉(zhuǎn)到的位置進(jìn)行有效操作完的下一條指令,為了實(shí)現(xiàn)如C語言中的if語句。
最終你的指令是寫成一個(gè)case語句中或者寫成一個(gè).coe文件的,coe文件直接寫入數(shù)據(jù)存儲(chǔ)器中,
例如
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,
最終燒錄驗(yàn)證就實(shí)現(xiàn)了用CPU跑一個(gè)小程序了。
-
FPGA
+關(guān)注
關(guān)注
1629文章
21744瀏覽量
603664
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論