第一次互评作业:MIPS汇编程序设计

Posted lan126

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一次互评作业:MIPS汇编程序设计相关的知识,希望对你有一定的参考价值。

  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
 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 *    

 



 

 

以上是关于第一次互评作业:MIPS汇编程序设计的主要内容,如果未能解决你的问题,请参考以下文章

优化系列汇编优化技术:MIPS架构纯汇编优化及demo

在 mips 汇编器中编写棋盘格的 bmp 文件

优化系列MIPS架构汇编优化总结

使用乘法和除法从小到大的字节序-MIPS汇编

从 C 编译器理解 MIPS 汇编代码

在 MIPS 上对 C++ 和汇编代码进行微架构分析