--- tags: RISCV, 伴學松, 伴學松活動記錄 --- # 從0到有製作自己的CPU!! 第九周活動記錄 20220830 [TOC] # 直播紀錄連結 {%youtube GrFwmOvZ1TM%} ## 出席 - [x] KIM_WENG - [x] 名名 - [ ] chuan - [x] bill503084699 - [ ] 楓糖 - [x] 謝祥辰 - [x] 黑貓 - [ ] sixkwnp - [ ] Bonki - [x] ouo314 - [x] Willwho - [ ] GYLABA - [x] mikuthebest - [x] Penquuin - [x] 葉子 - [ ] painCake - [x] EZ4ENCE - [ ] 頂漿汗腺 - [x] 角角 - [ ] adam chen - [x] tom12138 # 討論內容 1. tom今天新學友分享立即數 2. [ tom12138 yt影片連結](https://www.youtube.com/watch?v=Lzaf4gofbos) 3. ouo實作 4. 講解tom用python做出來的程式來處理機器語言 5. efabless這個國外外包寫cpu的這個機構想要下次來分享(國外平台處裡cpu rv32i寫好剩下給她們處裡 處裡要額外收費 ) ## 1. 新增branch.v文件 • 文档 ![](https://i.imgur.com/Vw5qfTP.png) > 注意:除了`bltu`,`bgeu`外, 其他指令比较时需要使用$signed() • 部分真值表 | | en | op[2:0] | data1[31:0] | data2[31:0] | out | | ----------- | ---- | ------- | ---------------------- | -------------- | ---- | | otheropcode | 0 | x | x | x | 0 | | beq | 1 | 0x0 | 0x00000002 | 0x00000002 | 1 | | bne | 1 | 0x1 | 0x00000002 | 0x00000002 | 0 | | blt | 1 | 0x4 | 0xfffffff0(-16) | 0x00000010(16) | 1 | | bltu | 1 | 0x6 | 0xfffffff0(4294967280) | 0x00000010(16) | 0 | ## 2. decoder.v添加 * 修改alu的op连线名为aluop * 添加be, bop[2:0] * 添加Branch指令的判断 opcode: 1100011 * re1,re1 设置为enable: 读取用于计算, 送入branch对比 * we,设置为disable: 不需要读 * pce, enable: 将pc_next送入alu * imme, enable: 将imm送入alu * jumpe, disable: pc仅受branch_enable控制 * aluop, 8'h1: alu进行加法, imm+pc_next * be, enable: branch启动 * bop: prog[14:12] * imm 取值 ![](https://i.imgur.com/DqKL3hH.png) ![](https://i.imgur.com/W7Q71eV.png) ## 3. pc.v * 添加 input branch_en * branch_en或jmp_en为1时使用jmp_addr为pc ## 4. cpu.v拉线 * 加入branch模块 * alu修改名字 * decode(be)---------BRANCH_ENABLE----------->branch(en) * decode(bop)--------BRANCH_OPCODE---------->branch(op) * branch(out)---------BRANCH_JUMP_ENABLE---->pc(branch_en) * register(data1)--------------RS1------------------>branch(data1) * register(data2)--------------RS2------------------>branch(data2) > 小心branch收到得应该是RS1和RS2,不是DATA1, DATA2 ## 5. regFile.v 初始化 ```verilog integer i; initial begin for (i = 0; i<=31 ; i=i+1) begin regfile[i] = 'b0; end end ``` ## 6. CPU测试 * asm 代码, 写了几个loop, 把内容放在t0-t3中 ```assembly j count_in_t0 count_in_t0: li a0 64 li a1 63 li t0 0 addi a1 a1 1 addi t0 t0 1 beq a0 a1 -8 count_in_t1: li a2 -16 li a3 -18 li t1 0 addi a3 a3 1 addi t1 t1 1 bne a2 a3 -8 count_in_t2: li a0 1 li a1 -1 li t2 0 addi a1 a1 1 addi t2 t2 1 bge a0 a1 -8 count_in_t3: li a3 16 li a4 -16 li t3 0 addi a1 a1 1 addi t3 t3 1 bgeu a3 a4 -8 li t4 0 add t4 t4 t0 add t4 t4 t1 add t4 t4 t2 add t4 t4 t3 ``` * hex code ```text 00 40 00 6f // 0x0: jal x0 4 <count_in_t0> 04 00 05 13 // 0x4: addi x10 x0 64 03 f0 05 93 // 0x8: addi x11 x0 63 00 00 02 93 // 0xc: addi x5 x0 0 00 15 85 93 // 0x10: addi x11 x11 1 00 12 82 93 // 0x14: addi x5 x5 1 fe b5 0c e3 // 0x18: beq x10 x11 -8 ff 00 06 13 // 0x1c: addi x12 x0 -16 fe e0 06 93 // 0x20: addi x13 x0 -18 00 00 03 13 // 0x24: addi x6 x0 0 00 16 86 93 // 0x28: addi x13 x13 1 00 13 03 13 // 0x2c: addi x6 x6 1 fe d6 1c e3 // 0x30: bne x12 x13 -8 00 10 05 13 // 0x34: addi x10 x0 1 ff f0 05 93 // 0x38: addi x11 x0 -1 00 00 03 93 // 0x3c: addi x7 x0 0 00 15 85 93 // 0x40: addi x11 x11 1 00 13 83 93 // 0x44: addi x7 x7 1 fe b5 5c e3 // 0x48: bge x10 x11 -8 01 00 06 93 // 0x4c: addi x13 x0 16 ff 00 07 13 // 0x50: addi x14 x0 -16 00 00 0e 13 // 0x54: addi x28 x0 0 00 15 85 93 // 0x58: addi x11 x11 1 00 1e 0e 13 // 0x5c: addi x28 x28 1 fe e6 fc e3 // 0x60: bgeu x13 x14 -8 00 00 0e 93 // 0x64: addi x29 x0 0 00 5e 8e b3 // 0x68: add x29 x29 x5 00 6e 8e b3 // 0x6c: add x29 x29 x6 00 7e 8e b3 // 0x70: add x29 x29 x7 01 ce 8e b3 // 0x74: add x29 x29 x28 ``` * 测试结果 ```text regfile[5] t0 0x00000002 regfile[6] t1 0x00000002 regfile[7] t2 0x00000003 regfile[10] a0 0x00000001 regfile[11] a1 0x00000003 regfile[12] a2 0xfffffff0 regfile[13] a3 0x00000010 regfile[14] a4 0xfffffff0 regfile[28] t3 0x00000001 regfile[29] t4 0x00000008 ``` ## 实验结果 ![](https://i.imgur.com/6rb1l7Q.png) [schematic](https://drive.google.com/file/d/1TBCfGwa0wNbuTkMd78Xfcd_t21w8Aqx-/view?usp=sharing) # 本周作業 - tom12138的教學複習與額外教的內容 - ouo寫的code (branch) # 討論重點 1. 觀摩tom12138錄的影片來學習統整cpu以往所學的 2. ouo實作(branch) ## 點子 / 撇步 - 因為保留給C tyep 兩個bype的指令 如果沒有留就可以直接延後兩位? [name=tom12138m & 第二組] - function3 首先在input 內容裡面 [name=tom12138 & 第二組] - 對pc而言 都要跳位那判斷要是誰 ,傳給pc的訊號是給alu算,jump是直接回到pc,但branch是從register1 2 抓值給 會需要imm ....再回到alu因此branch 不是直接回pc [name=tom12138 & 第二組] - 拉線步驟 input output [name=tom1213 & 第二組] - 討論誰要實作code [name=tom12138 & 第二組] - 結果ouo 實作 [name=tom12138 & 第二組] - 講解tom作出來的程式 [name=tom12138 & 第二組] - 黑貓公告下次有國外平台會來分享cpu內容 9750單項目不曉得是單憑方毫米釐米來算價格 有的是看製成 stm32 [name=tom12138 & 第二組] - ouo實作code 用黑貓小號去當麥克風 [name=tom12138 & 第二組] - 翔丞接手ouo實作 branch講解 [name=tom12138 & 第二組] - 用vivado跑branch [name=tom1213 & 第二組] - 用vscode逐一講解alu Ddecode branch decode之間的關系 [name=tom12138 & 第二組] - 除錯中深入講解 [name=tom12138 & 第二組] # 聊天室連結 1. **https://ithelp.ithome.com.tw/articles/10273738** 2. **https://www.youtube.com/watch?v=Lzaf4gofbos** 3. **https://efabless.com/** 4. **http://www.alientek.com/productinfo/1434580.html** 5. **https://www.youtube.com/watch?v=8BCuRdTJ0PM** 6. https://ithelp.ithome.com.tw/articles/10273738 6. **https://github.com/375432636/accomdemy_rv32i** 7. **https://hackmd.io/@accomdemy/BJprQ8Xjc/https%3A%2F%2Fhackmd.io%2F%40accomdemy%2FrJyYw0O1o#%E5%AE%9E%E9%AA%8C%E7%BB%93%E6%9E%9C** # 聊天室圖片 1. ![](https://i.imgur.com/nRAKXLQ.png) 2. **![](https://i.imgur.com/hrxDa5y.png)** 4. **![](https://i.imgur.com/ZwYLszw.png)** 5. ![](https://i.imgur.com/Hj36tGM.png) 7. ![](https://i.imgur.com/j7nTiw0.jpg) 8. ![](https://i.imgur.com/v6EQHKO.png) # 聊天室內容 ![](https://i.imgur.com/1OndqGo.png) ![](https://i.imgur.com/v6lgJzv.png) ![](https://i.imgur.com/qwNYt1G.png) ![](https://i.imgur.com/ZAN3WML.png) ![](https://i.imgur.com/mCCceqm.png) ![](https://i.imgur.com/1b10Es9.png) ![](https://i.imgur.com/o4L8qXE.png) ![](https://i.imgur.com/VXJbQAB.png) ![](https://i.imgur.com/phDDq5x.png) ![](https://i.imgur.com/2M4ghmf.png) ![](https://i.imgur.com/FMfm7n4.png) ![](https://i.imgur.com/zOqPzuh.png) ![](https://i.imgur.com/oheWVj9.png) ![](https://i.imgur.com/6IaEI3r.png) ![](https://i.imgur.com/l8yEH9M.png) ![](https://i.imgur.com/V4ZgeIN.png) ![](https://i.imgur.com/87ko2WG.png) ![](https://i.imgur.com/DqDeNAv.png) ![](https://i.imgur.com/rOmK37t.png)