序
唉唉,又差一点把第三题做出来。猛攻 1h 以失败告终……不过起码通过了,开心~
第一题 CRR
| 31:26 |
25:21 |
20:16 |
15:11 |
10:6 |
5:0 |
| opcode |
rs |
rt |
rd |
0 |
funct |
| 000000 |
|
|
|
00000 |
101101 |
RTL 描述如下:
def:rotate_right(x,n):x循环右移n位if(rotate_right(GPR[rs],rs)≥rotate_right(GPR[rt],rt))thenGPR[rd]←rotate_right(GPR[rs],rs)elsethenGPR[rd]←rotate_right(GPR[rt],rt)endif
这题难点在于如何用 Verilog 实现循环右移这一操作。我的想法是开一个 reg 类型的临时变量 temp,先用一个循环把 x 的低 n 位放到 temp 的高 n 位,然后再用一个循环把 x 的剩下 32 - n 位放到 temp 的剩下 32 - n 位。
第二题 BRB
| 31:26 |
25:21 |
20:16 |
15:0 |
| opcode |
rs |
rt |
offset |
| 111100 |
|
|
|
RTL 描述如下:
def:reverse(x)将x高位与低位倒转byte←offset1..0temp←GPR[rs]7+8∗byte..8∗byteif(reverse(temp)mod2==0)thenPC←PC+4+sign_extend(offset∣∣02)elsethenPC←PC+4endifGPR[rt]←sign_extend(reverse(temp))
这题注意无条件写入 GPR[rt]。
第三题
忘抄题了www
本地测试是能过的,但评测就是出现了神秘的问题。唉唉,备战 P5 吧,下次就算没过我也要把题抄下来。