1 .data
2
3 string1: .asciiz
"*\n"
4
5
6 bstring: .asciiz #大写字母转换的字符串下同
7 "Alpha ",
"Bravo ",
"China ",
"Delta ",
"Echo ",
"Foxtrot ",
8 "Golf ",
"Hotel ",
"India ",
"Juliet ",
"Kilo ",
"Lima ",
9 "Mary ",
"November ",
"Oscar ",
"Paper ",
"Quebec ",
"Research ",
10 "Sierra ",
"Tango ",
"Uniform ",
"Victor ",
"Whisky ",
"X-ray ",
11 "Yankee ",
"Zulu "
12
13 boffset: .word #为了得到大写字母字符串数组的偏移量下同
14 0,
7,
14,
21,
28,
34,
43,
49,
56,
63,
71,
15 77,
83,
89,
99,
106,
113,
121,
131,
16 139,
146,
155,
163,
171,
178,
186
17
18
19 nstring: .asciiz
20 "zero ",
"First ",
"Second ",
"Third ",
"Fourth ",
21 "Fifth ",
"Sixth ",
"Seventh ",
"Eighth ",
"Ninth "
22
23 noffset: .word
24 0,
6,
13,
21,
28,
36,
43,
50,
59,
67
25
26
27 sstring: .asciiz
28 "alpha ",
"bravo ",
"china ",
"delta ",
"echo ",
"foxtrot ",
29 "golf ",
"hotel ",
"india ",
"juliet ",
"kilo ",
"lima ",
30 "mary ",
"november ",
"oscar ",
"paper ",
"quebec ",
"research ",
31 "sierra ",
"tango ",
"uniform ",
"victor ",
"whisky ",
"x-ray ",
32 "yankee ",
"zulu "
33
34 soffset: .word
35 0,
7,
14,
21,
28,
34,
43,
49,
56,
63,
71,
36 77,
83,
89,
99,
106,
113,
121,
131,
37 139,
146,
155,
163,
171,
178,
186
38
39
40
41 .text
42
43 loop:
44
45 li $v0,
12 #读字符
46 syscall
47
48 move $t2,$v0
49
50 move $t0,$t2 #如果是'?'就退出
51 li $t1,
63
52 beq $t0,$t1,exit
53
54 move $t0,$t2 #其他符号打印'*'
55 li $t1,
122
56 bgt $t0,$t1,other
57
58 move $t0,$t2
59 li $t1,
48
60 blt $t0,$t1,other
61
62 move $t0,$t2 #打印数字对应的字符串
63 li $t1,
57
64 ble $t0,$t1,number
65
66 move $t0,$t2
67 li $t1,
65
68 blt $t0,$t1,other
69
70 move $t0,$t2 #打印大写字母对应的字符串
71 li $t1,
90
72 ble $t0,$t1,big
73
74 move $t0,$t2
75 li $t1,
97
76 blt $t0,$t1,other
77
78 #print Lower case letters
79
80 addi $t0,$t0,-
97
81 la $t1,soffset
82 sll $t0,$t0,
2 #整型数组的下一个偏移量是+4所以左移2下同
83 add $t0,$t0,$t1
84 lw $t1,($t0) #取到对应的偏移量下同
85 la $t0,sstring
86 add $t0,$t0,$t1 #算出对应字符串的地址下同
87 move $a0,$t0
88 li $v0,
4
89 syscall
90 j loop
91
92 other:
93
94 la $a0,string1
95 li $v0,
4
96 syscall
97 j loop
98
99 number:
100
101 addi $t0,$t0,-
48
102 la $t1,noffset
103 sll $t0,$t0,
2
104 add $t0,$t0,$t1
105 lw $t1,($t0)
106 la $t0,nstring
107 add $t0,$t0,$t1
108 move $a0,$t0
109 li $v0,
4
110 syscall
111 j loop
112
113 #print Upper case letters
114 big:
115
116 addi $t0,$t0,-
65
117 la $t1,boffset
118 sll $t0,$t0,
2
119 add $t0,$t0,$t1
120 lw $t1,($t0)
121 la $t0,bstring
122 add $t0,$t0,$t1
123 move $a0,$t0
124 li $v0,
4
125 syscall
126 j loop
127
128 exit:
129
130 li $v0,
10
131 syscall
第一题的算法文字描述:
调用系统功能输入数据转换数据(1) 如果输入的是字母(A~Z,区分大小写)或数字(0~9),则将其转换成对应的英文单词(2) 若输入的不是字母或数字,转换成“*”,每输入一个字符,即时转换并在屏幕上显示,支持反复输入,直到按“?”键结束程序。
对应的伪码:
1 if(n<=
122)
2 if(n>=
48)
3 if(n<=
57)
4 goto number
5 if(n<
65)
6 goto '*'
7 else
8 if(n<=
90)
9 goto big
10 if(n<
97)
11 goto '*'
12 if(n>=
97)
13 goto small
14 else
15 goto '*'
16 else
17 goto '*'
转载于:https://www.cnblogs.com/tclan126/p/7159797.html