-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_ccmb.asm
457 lines (354 loc) · 12.3 KB
/
benchmark_ccmb.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#############################################################
#测试j,jal,jr指令,如需要可分开测试,执行正常应该是15个周期 revise date 2015/12/17 tiger
#############################################################
.text
benchmark_start:
addi $s1,$zero, 1 #测试j,jal,jr指令,如需要可分开测试,执行正常应该是15个周期
j jmp_next1
addi $s1,$zero, 1
addi $s2,$zero, 2
addi $s3,$zero, 3
jmp_next1:
j jmp_next2
addi $s1,$zero, 1
addi $s2,$zero, 2
addi $s3,$zero, 3
jmp_next2:
j jmp_next3
addi $s1,$zero, 1
addi $s2,$zero, 2
addi $s3,$zero, 3
jmp_next3:
j jmp_next4
addi $s1,$zero, 1
addi $s2,$zero, 2
addi $s3,$zero, 3
jmp_next4:jal jmp_count
######################################
#移位测试 需要支持超addi,sll,add,syscall,srl,sll,sra,beq,j,syscall revise date:2015/12/16 tiger
.text
addi $s0,$zero,1 #简单移位,循环测试,0号区域显示的是初始值1左移1位重复15次的值,1号区域是累加值
addi $s1,$zero,1
sll $s1, $s1, 31 #逻辑左移31位 $s1=0x80000000
###################################################################
# 逻辑右移测试
# 显示区域依次显示0x80000000 0x20000000 0x08000000 0x02000000 0x00800000 0x00200000 0x00080000 0x00020000 0x00008000 0x00002000 0x00000800 0x00000200 0x00000080 0x00000020 0x00000008 0x00000002 0x00000000
###################################################################
LogicalRightShift: #逻辑右移测试,将最高位1逐位向右右移直至结果为零
add $a0,$0,$s1 #display $s1 #逻辑右移测试,将最高位1逐位向右右移直至结果为零
addi $v0,$0,34 # display hex
syscall # we are out of here.
srl $s1, $s1, 2
beq $s1, $zero, shift_next1
j LogicalRightShift
shift_next1:
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
###################################################################
# 逻辑左移测试
# 显示区域依次显示0x00000004 0x00000010 0x00000040 0x00000100 0x00000400 0x00001000 0x00004000 0x00010000 0x00040000 0x00100000 0x00400000 0x01000000 0x04000000 0x10000000 0x40000000 0x00000000
###################################################################
addi $s1,$zero, 1 # 逻辑左移测试
LogicalLeftShift: #逻辑左移测试,将最低位1逐位向左移直至结果为零
sll $s1, $s1, 2
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
beq $s1, $zero, ArithRightShift
j LogicalLeftShift
###################################################################
# 算术右移测试
# 显示区域依次显示0x80000000 0xf0000000 0xff000000 0xfff00000 0xffff0000 0xfffff000 0xffffff00 0xfffffff0 0xffffffff
###################################################################
ArithRightShift: #算术右移测试,#算术移位测试,80000000算术右移,依次显示为F0000000,FF000000,FFF00000,FFFF0000直至FFFFFFFF
addi $s1,$zero,1 # 算术右移测试
sll $s1, $s1, 31 #逻辑左移31位 $s1=0x80000000
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 3 #$s1=0X80000000-->0XF0000000
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4 #0XF0000000-->0XFF000000
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4 #0XFF000000-->0XFFF00000
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
sra $s1, $s1, 4
add $a0,$0,$s1 #display $s1
addi $v0,$0,34 # display hex
syscall # we are out of here.
#############################################################
#走马灯测试,测试addi,andi,sll,srl,sra,or,ori,nor,syscall LED按走马灯方式来回显示数据
#############################################################
.text
addi $s0,$zero,1
sll $s3, $s0, 31 # $s3=0x80000000
sra $s3, $s3, 31 # $s3=0xFFFFFFFF
addu $s0,$zero,$zero # $s0=0
addi $s2,$zero,12
addiu $s6,$0,3 #走马灯计数
zmd_loop:
addiu $s0, $s0, 1 #计算下一个走马灯的数据
andi $s0, $s0, 15
#######################################
addi $t0,$0,8
addi $t1,$0,1
left:
sll $s3, $s3, 4 #走马灯左移
or $s3, $s3, $s0
add $a0,$0,$s3 # display $s3
addi $v0,$0,34 # system call for LED display
syscall # display
sub $t0,$t0,$t1
bne $t0,$0,left
#######################################
addi $s0, $s0, 1 #计算下一个走马灯的数据
addi $t8,$0,15
and $s0, $s0, $t8
sll $s0, $s0, 28
addi $t0,$0,8
addi $t1,$0,1
zmd_right:
srl $s3, $s3, 4 #走马灯右移
or $s3, $s3, $s0
addu $a0,$0,$s3 # display $s3
addi $v0,$0,34 # system call for LED display
syscall # display
sub $t0,$t0,$t1
bne $t0,$0,zmd_right
srl $s0, $s0, 28
#######################################
sub $s6,$s6,$t1
beq $s6,$0, exit
j zmd_loop
exit:
add $t0,$0,$0
nor $t0,$t0,$t0 #test nor ori
sll $t0,$t0,16
ori $t0,$t0,0xffff
addu $a0,$0,$t0 # display $t0
addi $v0,$0,34 # system call for LED display
syscall # display
#################################################################################
#本程序实现0-15号字单元的降序排序,此程序可在mars mips仿真器中运行
#运行时请将Mars Setting中的Memory Configuration设置为Compact,data at address 0
#
#################################################################################
.text
sort_init:
addi $s0,$0,-1
addi $s1,$0,0
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
sw $s0,0($s1)
addi $s0,$s0,1
addi $s1,$s1,4
addi $s0,$s0,1
add $s0,$zero,$zero
addi $s1,$zero,60 #排序区间
sort_loop:
lw $s3,0($s0)
lw $s4,0($s1)
slt $t0,$s3,$s4
beq $t0,$0,sort_next #降序排序
sw $s3, 0($s1)
sw $s4, 0($s0)
sort_next:
addi $s1, $s1, -4
bne $s0, $s1, sort_loop
add $a0,$0,$s0 #display $s0
addi $v0,$0,34 # display hex
syscall # we are out of here. DISP: disp $r0, 0
addi $s0,$s0,4
addi $s1,$zero,60
bne $s0, $s1, sort_loop
addi $v0,$zero,10 # system call for pause
syscall # we are out of here.
#############################################
# insert your ccmb benchmark program here!!!
#############################################
#C1 instruction benchmark
#SLLV移位测试 revise date:2018/3/12 tiger
#依次输出 0x00000876 0x00008760 0x00087600 0x00876000 0x08760000 0x87600000 0x76000000 0x60000000 0x00000000
addi $t0,$zero,1
addi $t1,$zero,3
addi $s1,$zero, 0x876
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
addi $t3,$zero,8
sllv_branch:
sllv $s1,$s1,$t0 #测试指令
sllv $s1,$s1,$t1 #测试指令
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
addi $t3,$t3, -1
bne $t3,$zero,sllv_branch
addi $v0,$zero,10 # system call for exit
syscall # we are out of here.
#C2 instruction benchmark
#xori 测试 revise date:2018/3/12 tiger
# 0x00007777 xor 0x0000ffff = 0x00008888
# 0x00008888 xor 0x0000ffff = 0x00007777
# 依次输出 0x00007777 0x00008888 0x00007777 0x00008888 0x00007777 0x00008888 0x00007777 0x00008888
# 0x00007777 0x00008888 0x00007777 0x00008888 0x00007777 0x00008888 0x00007777 0x00008888 0x00007777
addi $t0,$zero,-1
addi $s1,$zero, 0x7777
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
addi $t3,$zero, 0x10
xori_branch:
xori $s1,$s1, 0xffff #先移1位
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
addi $t3,$t3, -1
bne $t3,$zero,xori_branch #循环8次
addi $v0,$zero,10 # system call for exit
syscall # we are out of here.
#Mem instruction benchmark
#SB 测试
#依次输出 0x00000000 0x00000001 0x00000002 0x00000003 0x00000004 0x00000005 0x00000006 0x00000007 0x00000008 0x00000009 0x0000000a 0x0000000b 0x0000000c
# 0x0000000d 0x0000000e 0x0000000f 0x00000010 0x00000011 0x00000012 0x00000013 0x00000014 0x00000015 0x00000016 0x00000017 0x00000018 0x00000019
# 0x0000001a 0x0000001b 0x0000001c 0x0000001d 0x0000001e 0x0000001f 0x03020100 0x07060504 0x0b0a0908 0x0f0e0d0c 0x13121110 0x17161514 0x1b1a1918 0x1f1e1d1c
addi $t1,$zero,0 #init_addr
addi $t3,$zero,32 #counter
#sb写入 01,02,03,04
addi $s1,$zero, 0x00 #
addi $s2,$zero, 0x01 #
sb_store:
sb $s1,($t1)
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
add $s1,$s1,$s2 #data +1
addi $t1,$t1,1 # addr ++
addi $t3,$t3,-1 #counter
bne $t3,$zero,sb_store
addi $t3,$zero,8
addi $t1,$zero,0 # addr
sb_branch:
lw $s1,($t1) #读出数据
add $a0,$0,$s1
addi $v0,$zero,34 # system call for print
syscall # print
addi $t1,$t1,4
addi $t3,$t3, -1
bne $t3,$zero,sb_branch
addi $v0,$zero,10 # system call for exit
syscall # we are out of here.
#Branch instruction benchmark
#bgtz 测试 大于零跳转 递减运算 ,从正数开始向零运算 revise date:2018/3/12 tiger
#依次输出0x0000000f 0x0000000e 0x0000000d 0x0000000c 0x0000000b 0x0000000a 0x00000009 0x00000008 0x00000007 0x00000006 0x00000005 0x00000004 0x00000003 0x00000002 0x00000001
addi $s1,$zero,15
bgtz_branch:
add $a0,$0,$s1
addi $v0,$zero,34
syscall # 输出当前值
addi $s1,$s1,-1
bgtz $s1,bgtz_branch #当前测试指令
addi $v0,$zero,10
syscall # 程序暂停或退出
#MIPS处理器实现中请用停机指令实现syscall
jmp_count: addi $s0,$zero, 0
addi $s0,$s0, 1
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 2
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 3
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 4
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 5
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 6
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 7
add $a0,$0,$s0
addi $v0,$0,34 # display hex
syscall # we are out of here.
addi $s0,$s0, 8
add $a0,$0,$s0
addi $v0,$0,34 # display hex
addi $v0,$0,34 # display hex
syscall # we are out of here.
jr $31