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
###############################################################################
# File : clz.asm
# Project : MIPS32 MUX
# Author: : Grant Ayers (ayers@cs.stanford.edu)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'clz' instruction.
#
###############################################################################
.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status
#### Test code start ####
lui $t2, 0xffff # 0
ori $t2, 0xffff
ori $t3, $0, 0x0100 # 23
lui $t4, 0x0700 # 5
lui $t5, 0x0f00 # 4
lui $t6, 0x7fff # 1
ori $t7, $0, 0 # 32
clz $s2, $t2
clz $s3, $t3
clz $s4, $t4
clz $s5, $t5
clz $s6, $t6
clz $s7, $t7
addiu $s2, 0
addiu $s3, -23
addiu $s4, -5
addiu $s5, -4
addiu $s6, -1
addiu $s7, -32
or $v1, $s2, $s3
or $v1, $v1, $s4
or $v1, $v1, $s5
or $v1, $v1, $s6
or $v1, $v1, $s7
sltiu $v0, $v1, 1
#### Test code end ####
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'
$done:
jr $ra
nop
.end test